Apache-PHP max_execution_time fatal exception handling - php

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

Related

How to overcome maxreceivedmessagesize using php soapclient on linux

Hi I am interrogating a windows service on a remote IIS server from my Linux server using PHP soapclient.
Everything's working fine except when I make a request that returns a large chunk of data, I get the following message:
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
Is there something I can do with SoapClient to increase this value? I assume that it is at my end that the problem is arising...? Everything I read says to 'increase the MaxReceivedMessageSize in the appropriate web.config or app.config'. I don't have anything like that here on the client-side, just a couple of lines of PHP that make the call using the PHP soap class.
Any help welcome!

PHP ftp_delete() generates warning "Command okay"

I can not find any answer to this as most problems revolve around a file not existing or a delete process not working.
I have an FTP device where I generate a file with an PHP script. After that, I try to FTP in, get the file and after that, delete it.
This all works fine, I can connect, get the file and save it locally and then delete it. Except for one thing, the ftp_delete() function results in a warning.
PHP gives me the following, when executing the script:
A PHP Error was encountered
Severity: Warning
Message: ftp_delete(): Command okay
I looked up the error code, it means it was successful. And it was because the file is deleted on the FTP device.
So why does this generate an PHP error?
Cheers.
The RFC 959 (FTP specification) mandates that on a successful completion of the DELE command, the server should respond with 250 status code.
The PHP FTP implementation is very strict, yielding a warning on any other code, even if it indicates a success (2xx class).
Your server probably uses some other 2xx code, like a generic 200 Command okay.

php in free(): error: chunk is already free

I have developed a script that uses php's imap_search and when it gets to the stage of finding the emails with the function imap_search() i get a error being produced
php in free(): error: chunk is already
free
Abort trap: 6 (core dumped)
This script requires to be run through a cron, But when it does it does that above error and seems to abort the script, If i run from the browser it has this error inside the error logs but still runs the script in full.
Below is the line it is failing on:
$this->mailbox_emails = imap_search($this->mailbox_stream,'ALL');
This is an internal php error. File a bug on the imap module (if you want it fixed fast, include an SSCCE).
Also note that this is a memory corruption issue, which is usually caused (long) before it is noticed. Therefore, the imap_search function is probably not the buggy one; the imap_* function you used just before it is a good candidate.

PHP: Implications of a abrupt termination of a request by a *fatal* error

I'm experiencing a strange situation.
My application logs lot of trace logs to a file. (I don't know exactly how, I use my frameworks logger. Can check this though)
Problems is, when an application is terminated by a fatal error (only fatal) [example - "Fatal error: Call to a member function someFunction() on a non-object"] , I end up with no logs, even logs that should have been recorded much earlier during the execution of my script.
(Yes, I tried to flush logs, this doesn't help either. It looks like the termination of the application by a fatal error, somehow cancels writing to files done at earlier points of the application.
Any ideas what goes on here?
Thank you
A Fatal Error is... well... Fatal : it stops the execution of the script, which will not do anything that should have been done.
In your case, I suppose your logging framework logs into memory -- and that this in-memory log is only written to the file when the processing of the request is done.
Some logging mecanisms do that, to avoid writing to a file several times, at different points during the generation of the response (which means keeping the file locked, to avoid concurrency problems ; or opening-closing-reopening-reclosing-... it)
As you get a Fatal Error, the normal operation that should be done at the end of the response's generation is not called -- and, so, the in-memory log is not written to the file.
Now, the only way to know for sure would be to take a look at the logging mecanisms of your Framework ;-)
Apparently, the fatality of the fatal error that Pascal mentioned, is not 100% fatal.
The below allowed me to have my logs even on fatal errors:
function correctShutdown()
{
logger->flush();
}
register_shutdown_function('correctShutdown');

Zend session_start gives Fatal error: Exception thrown without a stack frame in Unknown on line 0

When running a Zend application locally I get Fatal error: Exception thrown without a stack frame in Unknown on line 0, i traced that error to a line $startedCleanly = session_start();
I can't get through it, when I restart the server and reload the page I do not get the error, but on every other reload I get it, I looked into a php/tmp dir too see if there are any files, and as I see they aren't there. I think that session isn't written but when I try just a simple test.php file with session_start(); line, without zend framework, I see that there is a file created in that dir.
I really don't know where to go next.
Happens when your destructor or error handler throws an exception. That can happen for multiple reasons depending on your exact setup and method for session storage you're using. For example the session directory is not writeable or does not exist, database is not accessible or fields are invalid, redis does not respond, etc.
So, check your settings and look for something that would prevent saving the session data.
More elaborate description can be found here.
I know this post is old, but I've just figured out that I was getting "Fatal error: Exception thrown without a stack frame in Unknown on line 0" because my 'modified' and 'lifetime' columns were of type 'timestamp without time zone' when they should have been 'integer' (I'm using Postgres 9 BTW)
Hope this helps someone.
The problem could also be a disk full problem !!!

Categories