This is possible using the Range header if the server supports it. See HTTP 1.1 spec . You want to send the header in the following format in the request:
Range: bytes=-50000
This will give you the last 50,000 bytes. Adjust everything you need.
You can specify this header in file_get_contents using context. For instance:
// Create a stream $opts = array( 'http'=>array( 'method' => "GET", 'header' => "Range: bytes=-50000\r\n" ) ); $context = stream_context_create($opts); // Open the file using the HTTP headers set above $file = file_get_contents('http://www.example.com/', false, $context);
source share