简体   繁体   中英

Apache-PHP max_execution_time fatal exception handling

I have a PHP module that fetches data from an Oracle DB, using the call oci_Execute(statement);

Now based on the search parameters provided by the user the search can sometimes takes more than 30 minutes. In such cases I want to cancel the search (at PHP level) and notify the user to reconsider the search params.

I attempted that by setting the PHP timeout variable max_execution_time in php.ini file. I have set up a ErrorDocument 404 redirect in the apache httpd.conf file (and it works fine with not found php pages). However, when the php times out and the oci_execute is still processing, PHP throws a fatal exception and crashes.

I have already tried try/catch and came to know that it doesn't work for fatal errors. I have tried registering a shutdown function via register_shutdown_function , it is never reached after the fatal error. I have tried setting apache timeout directives but they never take effect in the presence of PHP scripts.

I want either apache or PHP to respond with an error code and redirect to a page saying 'dear user please reconsider your search parameters' :) at the moment I see a fatal exception after timeout generated at oci_Execute line.

Rephrasing the question; how can I get out of the oci_execute call without a fatal exception, anything but a fatal exception will work.

At the Oracle database level, you can set a resource limit by altering the Profile. You should be able to trap the "error" from Oracle when you hit the resource limit.

ALTER PROFILE: http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_2008.htm#SQLRF00813

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM