I want to make PHP request GET asynchronous, but my version PHP is 5.2.13 and the version of curl is 7.16.4, that has many limits.
I tried:
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
But it does not work. As I know, that just works from PHP 5.2.3
So I read the other solution fsockopen:
function curl_request_async($url, $params, $type='POST')
{
if (count($params)>0){
$post_params = array();
foreach ($params as $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 the path for a GET request
if(('GET' == $type)&& isset($post_string)) $parts['path'] .= '?'.$post_string;
$out = "$type ".$parts['path']." HTTP/1.1
";
$out.= "Host: ".$parts['host']."
";
$out.= "Content-Type: application/x-www-form-urlencoded
";
$out.= "Content-Length: ".strlen($post_string)."
";
$out.= "Connection: Close
";
// Data goes in the request body for a POST request
if ('POST' == $type && isset($post_string)) $out.= $post_string;
fwrite($fp, $out);
fclose($fp);
}
that works with POST but that does not work with GET. I want to make the request GET asynchronous
Anyone can help me ?
Thank you so much