Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PHP Curl request not to wait?

Tags:

php

curl

I've a PHP function which fetches a Curl request. This request sometimes take longer time than expected and hence my php function takes longer to return.

In my particular case, output of curl request is not important. So is it possible with curl just to place a request and proceed without waiting for curl_exec() to finish?

like image 227
understack Avatar asked Apr 26 '10 06:04

understack


1 Answers

PHP does not support multi-threading, so this is not possible. You can, however, limit the amount of time cURL will execute.

$max_exe_time = 250; // time in milliseconds
curl_setopt($curl_handle, CURLOPT_TIMEOUT_MS, $max_exe_time);

You can read about this configuration option and others: http://php.net/manual/function.curl-setopt.php

like image 141
erisco Avatar answered Sep 23 '22 03:09

erisco