I send an Ajax request with a Kurl and set a timeout of 10 seconds. Is there any parameter that returns some kind of response at timeout? Since I cannot catch this timeout, the request returns an empty response.
1 answer
CURLOPT_CONNECTTIMEOUT - The number in seconds to wait before connecting. 0 for no end connection.
CURLOPT_TIMEOUT - How long cURL will run in seconds
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); curl_setopt($ch, CURLOPT_TIMEOUT, 400); //timeout in seconds Time Out Fishing Solutions
<?php if (!isset($_GET['foo'])) { // Client $ch = curl_init('http://localhost/test/test_timeout.php?foo=bar'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_NOSIGNAL, 1); curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); $data = curl_exec($ch); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); curl_close($ch); if ($curl_errno > 0) { echo "cURL Error ($curl_errno): $curl_error\n"; } else { echo "Data received: $data\n"; } } else { // Server sleep(10); echo "Done."; } ?> - Your option helped thanks! - quaresma89
- Thank you, can you tick the box to help others? - L. Vadim
- I marked it right away as the right answer. - quaresma89
- tick is not visible, you can do it again - L. Vadim
|