How do I close a Curl connection that does not answer after a certain amount of time

Hi,

We do payment processing via Paypal/verisign and since Friday their service has been having near 99% problem :frowning:
Resulting in payments passed to them for processing not being processed, that is they send no response back after one passes to them the payment information for processing resulting in our server hanging. So what I need to do is to close the connection to them if they fail to respond within certain amount of time, so that at least our server will not hag waiting for them to reply.

So my question is: how do I close a Curl connection that does not answer after a certain amount of time?

We have a transaction communication like this:


		$fp = fsockopen ('ssl:/pp.com', 443, $errno, $errstr, 120); 

		fputs ($fp, $req);     
		while (!feof($fp))     {           
			$res .= fgets($fp, 100);     
			}  

		$result1 =  getValue($res, 'RESULT='); 


		fclose($fp); 

How do I test to see that the server pp.com has not responded within say 30 seconds and thus close fclose($fp); based on this lack of response?

Regards,

P.S., Do not do your payment processing via Paypal/Verisign, since they are totally unprofessional with their service since as noted above their service in regard to this critical issue of payment processing has been malfunctioning since Friday/Mar/18, resulting in countless lost sales :frowning:
And worst head aches :frowning:

fsockopen() has a timeout parameter

The code youโ€™re showing is not anything to do with curl. curl is a seperate library of functions designed for http connections.

If you are actually using curl and that code above is for something else then you need to look at curl_setopt() and CURLOPT_CONNECTTIMEOUT

Hi,

Well as you can see from the Code that I provided I have the timeout value already set at 120. However it does not seem to work, since after 120 Seconds go by and there is NO reply from the server, the connection is not closed and the user browser just hangs.

So it seems that the built-in timeout is not doing its job and that one should use an extra Php code to chck out for too much time having elapsed and close the connection that way.

Regards,

I missed that. Looking at the manual you may need to use stream_set_timeout()

Why not just actually use curl instead? - It is designed for this sort of stuff.