SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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
    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:
    Code PHP:
    		$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
    And worst head aches

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fsockopen() has a timeout parameter
    aaron-fisher.com - PHP articles and more

  3. #3
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  4. #4
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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,

    Quote Originally Posted by aamonkey View Post
    fsockopen() has a timeout parameter

    Anoox search engine volunteer

    www.anoox.com

  5. #5
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WorldNews View Post
    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.
    I missed that. Looking at the manual you may need to use stream_set_timeout()
    aaron-fisher.com - PHP articles and more

  6. #6
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just actually use curl instead? - It is designed for this sort of stuff.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •