1

I created a script which get a content of something web page but this script get full content (~25.000 characters). My script do it with 4 sites so finally I get 100.000 characters but I need only first 100 characters from every web page. How I can tell CURL to get only fisrt 100 characters and no more ? I think it will be faster solution because now I have to wait ~11 seconds. It's too much for me.

Here is my script:

$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'https://example.com/index.php?id='.$part.'&asmp3=1&part='.$i.'&t='.get_miliseconds());
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($c, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($c, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$code = curl_exec($c);
curl_close($c);

What I have to add to my script to get only first 100 characters as response?

Thanks.

EDIT:

No, it's not duplicate from this URL: How to partially download a remote file with cURL? . I don't download any FILE but content of web page... It's not the same. It's not binary file but HTML content. I tried with solution from this URL but it's doesn;t work.

Community
  • 1
  • 1
Majkson
  • 227
  • 4
  • 15
  • 3
    Possible duplicate of [How to partially download a remote file with cURL?](http://stackoverflow.com/questions/2032924/how-to-partially-download-a-remote-file-with-curl) – iainn Jul 06 '16 at 10:13
  • No, it's not duplicate. I don't download any FILE but content of web page... It's not the same. It's not binary file but HTML content. I tried with solution from this URL but it's doesn;t work. – Majkson Jul 06 '16 at 10:16
  • If you know the encoding of the page you can stick with the solution provided above. – wazelin Jul 06 '16 at 10:25
  • @Wazelin I don't know what I have to do exactly ? – Majkson Jul 06 '16 at 10:37
  • 2
    What the downloaded "thing" is is irrelevant. If you have problems, the web server likely doesn't support partial downloads for dynamically generated content... – Karoly Horvath Jul 06 '16 at 10:42
  • When I do everything as in this URL, the content of this page is printing on my screen. I would like to get this content as $code. I can't do it because I have to checked `CURLOPT_RETURNTRANSFER` as FALSE because when I don't do it, solution form this url doesn't work. That's all... – Majkson Jul 06 '16 at 10:47
  • it is `printing(sic)` on your screen because is has en echo in the write callback. I easily modified `your-code` + `that-code` and got 100 bytes of `this-page`. But technically you are right , it is not 100% duplicate. – YvesLeBorg Jul 06 '16 at 11:36
  • Can you show your source ? – Majkson Jul 06 '16 at 11:37
  • 1
    @YvesLeBorg your answer was helpful and I wanted vote for your answer but you deleted it. Exactly thanks for your help, your code works fine. – Majkson Jul 06 '16 at 12:35

0 Answers0