This statement is superdense:
while(curl_exec($Resource)){ break; }
Instead, just keep the return value for future reference:
$result = curl_exec($Resource);
The while
helps nothing. So, now to your question: you can tell curl
that it should take only some bytes from the body and then leave. This can be achieved by reducing the value of CURLOPT_BUFFERSIZE
to a small value and using the callback function to report this, it should stop:
$withCallback = array( CURLOPT_BUFFERSIZE => 20, # ~ value of bytes you'd like to get CURLOPT_WRITEFUNCTION => function($handle, $data) { echo "WRITE: (", strlen($data), ") $data\n"; return 0; }, ); $handle = curl_init("http://stackoverflow.com/"); curl_setopt_array($handle, $withCallback); curl_exec($handle); curl_close($handle);
Conclusion:
WRITE: (10) <!DOCTYPE
Another option is to make a HEAD request using CURLOPT_NOBODY
, which will never receive the body. But this is not a GET request.
Connection timeout settings are how long it takes until the connection time is up. A connection is a phase until the server accepts input from curl, and curl begins to know what the server is doing. This is not related to the phase where curl retrieves data from the server, which
CURLOPT_TIMEOUT
maximum number of seconds to execute cURL functions.
In the PHP manual, you will find a long list of available options: curl_setopt
& shy; Docs .
source share