T
T
Thegaar2016-03-12 14:39:47
PHP
Thegaar, 2016-03-12 14:39:47

What is faster curl in php to get the body?

Do you guys have ready-made solutions that will get the page faster than curl? I understand that a lot depends on the bandwidth of the channel of both the local machine and the server from which I receive the body. But still?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
asd111, 2016-03-12
@asd111

curl_multi_exec

T
ThunderCat, 2016-03-12
@ThunderCat

if post file_get_contents() is not needed, maybe a little faster

V
Vitaly Artemyev, 2016-03-12
@Vitaly48

You can try fsockopen , it might be faster, but the difference can be so small that it's much more efficient to increase the bandwidth.
All in all, it's up to you.
Here is the code:

<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?>

D
Dimonchik, 2016-03-12
@dimonchik2013

nothing in PHP
in Python - asynchronous engines, but everything is also relative, for a particular page there is little difference, for a heap, yes through a proxy - it makes sense

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question