Hey! I'm using PHP to call a webservice that sadly gives me a lot of timeouts.

I want to try and "catch" these timeouts and give a softer timeout error with a predefined page where I can tell the user that the service gave a timeout and that he must re-submit his application. Or where I can myself just reload and make a new attempt until it goes through.

I'm using Nusoap and it gives the user a blank Fatal error-page refering to a line number when it times out.

So my question is, can I somehow interrupt the "Fatal error" / timeout message?

    Now answer? I assume there's no solution for this then?

      Swedie wrote:

      Now answer? I assume there's no solution for this then?

      There is a solution, I think 😃
      Personally, I have never experienced this situation,
      so can not tell.

      My solution has always been:

      try make my php scripts not to timeout
      ... sometimes while increase the time limit settings
      there are several such settings you can change,
      using [man]ini_set/man

      for exampeles and further references and readings,
      try
      [man]set_time_limit/man

        Afraid I have no answer, since I don't know what exactly your code does and therefore do not know what sort of error-trapping you could/should do.

        Does it throw an exception you could catch in a try/catch block? Does some function/method return false on failure that you should be checking for before calling the function/method that fails?

          There is already a timeout limit that you can set yourself... but I need to know how to run some type of command that can detect a timeout and give me an option to write out "Please try again" or whatever. Something better than an interrupted page.

          The error says:

          Fatal error: Maximum execution time of 45 seconds exceeded in C:.......\nusoap.php on line 2916

            The row it fails on is:
            $tmp = fgets($this->fp, 256);

            I can of course add a @ before and it would look like this: $tmp = @fgets($this->fp, 256);
            But all that does is remove the Fatal error and it will still stop the page from loading...

            arghh!

            Also tried:
            if($tmp = @fgets($this->fp, 256)) {
            //success
            } else {
            print "Något gick fel";
            }

            But it still kills the page load

              I'd probably look into using the [man]cURL[/man] functions to make the request. Then you could use the [man]curl_setopt[/man] CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT options to limit how long it will try to get the reponse. Then check the response or possibly something like [man]curl_errno[/man] to see if it succeeded or failed, and continue from there accordingly.

                Write a Reply...