0

I am developing a web service where I need to call an Oracle procedure in PHP. The Oracle procedure will take time to process and after completion it will write in a table.

How do I return an error in the web service response if the procedure call is taking too much time?

Note: I am stuck with PHP 5.2 and I cannot install cURL.

aliirfaan
  • 156
  • 5
  • php has a default time limit of 30 for entire script execution, is this enough? you can also modify it per script if you haven't disabled that functionality.. http://php.net/set_time_limit – Dale Mar 14 '18 at 11:16
  • You can set the general time limit with set_time_limit(); A more specific solution may be found in this thread: https://stackoverflow.com/questions/10587323/timeout-a-function-in-php - I guess you can manage it by utilising the pcntl_alarm() function. – Flocke Mar 14 '18 at 11:18
  • You cannot catch a max execution time error. The scripts just stops as well as all processing that follows. I need to return something, like a message if it happens. – aliirfaan Mar 14 '18 at 16:59
  • A combination of a user profile in the DB and sqlnet.ora parameters like recv_timeout are the best way. PHP's max_execution time is the time used for PHP code, and doesn't/didn't get checked when calls are waiting for the DB. – Christopher Jones Mar 15 '18 at 09:57

2 Answers2

0

Did you consider using http://php.net/manual/en/function.set-time-limit.php ?

Sets the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.

You can set it for your specific script for less than 30s, so it stops after e.g. a few seconds. And then you just handle empty response / error response.

Lis
  • 555
  • 4
  • 26
0

In php.ini default execution time limit is 30 seconds... Customise it & write your code in try catch & handle exception with customise error message.

Ashu
  • 1,320
  • 2
  • 10
  • 24