Send Request after x seconds

0

Good morning, I am sending a request xml to a webservice through PHP, what I need is that if they have passed x seconds and no response has been received from the webservice, cancel that request and send me a different one, how can I do it?

Greetings!

    
asked by daniel ascencio 20.11.2018 в 17:09
source

2 answers

1

I do not know what your purpose is, but Using timeout to request one or another request is not as good practice, usually timeout should be used to 'catch' service response errors and prevent your server from hanging up waiting for a response

If there is no other option, you can achieve what you want:

You can use the curl for PHP and use the CURLOPT_TIMEOUT option to assign a response time .

To run a certain code when the% co_of% ends, you should use timeout .

$ch = curl_init();
$timeout = 5; //segundos
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);

$data = curl_exec($ch);

if (curl_errno($ch) == 28){ // 28 -> CURLE_OPERATION_TIMEDOUT
    //timeout, código para el segundo request
}

curl_close($ch);

PHP Curl

Curl Errno

    
answered by 20.11.2018 в 18:58
0

Best regards, you can use this function sleep (10); available in php 5.4 to 5.7  after shipment I'm attentive.

write me and we keep looking

    
answered by 20.11.2018 в 18:26