M
M
misha912012-03-30 15:34:49
PHP
misha91, 2012-03-30 15:34:49

file_get_contents not getting page completely?

file_get_contents does not get the entire page, only part of the page. What could be the problem?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Stdit, 2012-03-30
@misha91

The server gives only the first chunk, apparently it is crookedly configured. Neither curl nor wget can download it in text form. The browser gets the full page because it uses gzip. To get a full page via gzip in php, you need to do something like this:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://nightout.ru/photoreport/alpen-grotte/after-party-zolotoi-sostav-0?page=0');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip'));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
echo gzinflate(substr($result,10));

D
dali, 2012-03-30
@dali

do not suffer with file_get_contents, use cURL to get the page, for me it even works faster than file_get_contents. Switched to cURL after errors like PHP Warning: file_get_contents('...'): failed to open stream: Connection timed out in /var/www/…

S
Sincous, 2012-03-30
@Sincous

I used file_get_contents, fsockopen, then, as noted above, I switched to cURL, and even this did not solve the problem. (used on the jump of images from VKontakte).
Therefore, for pages where authorization is not needed, but you only need to receive content, I recommend simply
<?php
$l = file($url);
$content = implode('', $l);
?>

M
Meliborn, 2012-03-30
@Meliborn

In the absence of details in the question.

K
Konstantin, 2012-03-30
@Norraxx

1. www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen ?
2. error_reporting(E_ALL); ini_set('display_errors', true) // this is so, maybe
3. Bad protocol is not HTTP 1.1 but 1.0? Transfer-Encoding:chunked? www.php.net/manual/en/context.http.php "PHP prior to 5.3.0 does not implement chunked transfer decoding.".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question