Reza Reza - 3 years ago 125
PHP Question

PHP cURL required only to send and not wait for response

I need a PHP cURL configuration so that my script is able to send requests and ignore the answers sent by the API.

// curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
//curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100);
$result = curl_exec($ch);
echo $result;
curl_close ($ch);

I tried adding:
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
//curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100);

But its not working properly and the API webserver is not receiving the requests.

The reason for this is I am sending large amount of requests to the API therefore my script is very slow because it waits for each and every request.

Any help is appreciated.

Answer Source


public function cccc($test=1) {
if($test==1) {
    $url = '';
    $curl = curl_init();                
    $post['test'] = 'test';
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt ($curl, CURLOPT_POST, TRUE);
    curl_setopt ($curl, CURLOPT_POSTFIELDS, $post); 

    curl_setopt($curl, CURLOPT_USERAGENT, 'api');
    curl_setopt($curl, CURLOPT_TIMEOUT, 1);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl,  CURLOPT_RETURNTRANSFER, false);
    curl_setopt($curl, CURLOPT_FORBID_REUSE, true);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1);
    curl_setopt($curl, CURLOPT_DNS_CACHE_TIMEOUT, 10); 

    curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);

    $data = curl_exec($curl);   
    echo $data;

} else {
    header("Connection: close\r\n");
    header("Content-Encoding: none\r\n");
    header("Content-Length: 1");

    $this->db->query('UPDATE new_hook_memory SET new=new+1 WHERE id=1');    




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download