Jump to content

$##! error handling - newbie needs help


php_ppt

Recommended Posts

My script displays results until I hit an error.  I continually get fatal timeout errors that I am unable to handle or ignore.  Yes I googled and found the custom error handler AND the simpler try/catch.  Still cant figure it out...

It has been 1 hour of playing with this without success so I have to ask  :P.  Please help.  thanks : )

 

try
{	
	if(($result=shell_exec("$commandLine")) == false)
	{
		echo "------>error";
		throw new Exception;
	}
	else
	{
		echo "---->good";
	}
}
catch (Exception $e)
{
	echo "@@@__>exception caught";
}

Link to comment
Share on other sites

I suspect that's not the code that is causing the errors, where's the rest of the stuff?

 

 

The called code is going to time out and there is nothing I can do about that.

I just want to be able to catch the timeOut error and continue with the PHP script.

:'(

 

 

Link to comment
Share on other sites

please delete thread.....reposted

Your other thread has been deleted due to this thread being the elder and having more responses.  Please do not double post.

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Thanks.....I did not mean to double post....I did request that this old one get deleted as it seemed to have stalled.  Will avoid in future.

 

I tried this and it did not work. 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

I found a couple of notes for "display_errors":

Note:

This is a feature to support your development and should never be used on production systems (e.g. systems connected to the internet).

Note:

Although display_errors may be set at runtime (with ini_set()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed.

 

I have read that fatal errors can be overcome.

I have read that fatal errors cannot be overcome.

 

?????

 

 

 

Link to comment
Share on other sites

ok....what is the function/procedure that is going to cause the time out?.....and why are you using it if you know it won't work? :o

 

It usually works, I did not write it and I am not about to mess with the module that is also used by others.

 

The script is calling an external function that is out of PHPs scope.

It could be a Windows exe, a website or a unix box or some sitting in a cubicle pressing a red button.

 

In BASH, VBS, C#, PERL and other languages these types of errors are expected and can be handled.

I am thinking PHP has a way to deal with these types of errors but if it can't I have to find another less elegant and clunky way.  :)

 

 

 

???????

 

 

Link to comment
Share on other sites

well with that being the case, all I can suggest is that you could reverse your TRY statement, so that it checks for the criteria exactly matching and throws the exeption for everything else, and you could have a shot with using set_time_limit() to controll the timeout errors that way, But it's not something I have ever used, so I can't advise any more than that. 

Link to comment
Share on other sites

well with that being the case, all I can suggest is that you could reverse your TRY statement, so that it checks for the criteria exactly matching and throws the exeption for everything else, and you could have a shot with using set_time_limit() to controll the timeout errors that way, But it's not something I have ever used, so I can't advise any more than that.

 

that will not work.  set_time_limit() adds to the default time limit and returns a fatal error if exceeded.

try/catch does nothing for fatal errors.

 

If I could get the shell_exe() to give up before the max time limit without fatal error that would work but I have not come across anything that allows the shell_exe() to do so.

 

???????

Link to comment
Share on other sites

Did you read the manual page for the set_time_limit() function? There you will find:

Parameters

 

seconds

The maximum execution time, in seconds. If set to zero, no time limit is imposed.

and

Note:

 

The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

 

Ken

Link to comment
Share on other sites

Did you read the manual page for the set_time_limit() function? There you will find:

Parameters

 

seconds

The maximum execution time, in seconds. If set to zero, no time limit is imposed.

and

Note:

 

The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

 

Ken

 

I read: http://ca.php.net/manual/en/function.set-time-limit.php

 

Where it states:

Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error.

 

I do not want to exceed the set 30 second timelimit.  I want it to run 30 seconds or less and fail with an error that allows the script to continue.  From what I have seen/read/been told: Fatal errors will stop the script.

 

 

????????

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.