Is it possible to get a partial response using PHP cURL?

Here is my code

$url = "partial_response.php"; $sac_curl = curl_init(); curl_setopt($sac_curl, CURLOPT_HTTPGET, true); curl_setopt($sac_curl, CURLOPT_URL, $url); curl_setopt($sac_curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($sac_curl, CURLOPT_HEADER, false); curl_setopt($sac_curl, CURLOPT_TIMEOUT, 11); $resp = curl_exec($sac_curl); curl_close($sac_curl); echo $resp; 

Partial_response.php

 header( 'Content-type: text/html; charset=utf-8' ); echo 'Job waiting ...<br />'; for( $i = 0 ; $i &#60; 10 ; $i++ ) { echo $i . '<br/>'; flush(); ob_flush(); sleep(1); } echo 'End ...<br/>'; 

From code trying to get a partial response from partial_response.php. what I want, I need to twist to return to me "Job waiting ..", and not wait until part_response.php completes the loop and returns all the data. so when I decrease CURLOPT_TIMEOUT below 11, I don't get any response at all. Please clarify my doubts. Thanks in advance.

+4
source share
2 answers

Later I realized that cURL cannot do what I want, I used stream_context_get_options to achieve what I wanted. Here it is, http://www.php.net/manual/en/function.stream-context-get-options.php .

+3
source

No, I'm afraid not. At least, not what I know, it is simply because PHP is a synchronous language, that is, you cannot skip tasks. (Ie curl_exec() will always - regardless of what - be executed until the request completes)

+1
source

Source: https://habr.com/ru/post/1480744/


All Articles