How to make PHP request GET asynchronous -


i want make php request asynchronous, version php 5.2.13 , version of curl 7.16.4, has many limits.

i tried:

curl_setopt($ch, curlopt_fresh_connect, true); curl_setopt($ch, curlopt_timeout, 1); 

but not work. know, works php 5.2.3

so read other solution fsockopen:

function curl_request_async($url, $params, $type='post')   {       if (count($params)>0){           $post_params = array();            foreach ($params $key => &$val) {             if (is_array($val)) $val = implode(',', $val);             $post_params[] = $key.'='.urlencode($val);           }           $post_string = implode('&', $post_params);       }        $parts    =   parse_url($url);        $fp = fsockopen($parts['host'],           isset($parts['port'])?$parts['port']:80,           $errno, $errstr, 30);        // data goes in path request       if(('get' == $type)&& isset($post_string)) $parts['path'] .= '?'.$post_string;        $out = "$type ".$parts['path']." http/1.1\r\n";       $out.= "host: ".$parts['host']."\r\n";       $out.= "content-type: application/x-www-form-urlencoded\r\n";       $out.= "content-length: ".strlen($post_string)."\r\n";       $out.= "connection: close\r\n\r\n";       // data goes in request body post request       if ('post' == $type && isset($post_string)) $out.= $post_string;        fwrite($fp, $out);       fclose($fp);   } 

that works post not work get. want make request asynchronous

anyone can me ?

thank much

why want make web request respond asynchronously? http requests meant responded synchronously.

i suggest if decouple long running request/process in backend front end response more snappy, use background php worker, on rabbitmq or beanstalkd, , have run long running process in background. http request return job id, can use make call check on status of long running job. additionally, when job done, can have make call notify caller job done, additional trigger or programming flow continued.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -