Page 1 of 1
try catch with the file function
Posted: Mon Jun 16, 2008 1:03 pm
by highjo
hi! there .i have a script that runs fie until the connection was very bad.now 've realised that the normal try and catch i've done are not working very well.so i cange it to :
Code: Select all
try
{
$response = file($authurl);
if(!$response) throw new Exception("We are facing some difficulties.please try again");
}
catch(Exception $e)
{
die($e->getMessage());
}
but i'm still having the same error
Fatal error: Maximum execution time of 60 seconds exceeded in
any idea?
Re: try catch with the file function
Posted: Mon Jun 16, 2008 1:32 pm
by John Cartwright
.. is the likely culprit. What are you trying to load? A large file?
Re: try catch with the file function
Posted: Mon Jun 16, 2008 1:52 pm
by highjo
actually, it's a api call. i use file with get parameter in the address to have an session id before i send sensitive info with that session id to another url with a proper curl request
Re: try catch with the file function
Posted: Mon Jun 16, 2008 2:02 pm
by John Cartwright
I would recommend using cURL to make the requests, and perhaps increase set_time_limit(0) if your having latency issues.
Re: try catch with the file function
Posted: Tue Jun 17, 2008 9:39 am
by highjo
i'll try that. the file does the job in one line.Don't you know any king of mesure to catch error either for file and curl if for example the connection break? as i say the normal try and catch seems not to be working, same if i throw the exception myself.Am i doing something wrong?
Re: try catch with the file function
Posted: Tue Jun 17, 2008 9:59 am
by Eran
You can only catch exceptions if they are thrown before a fatal error. Since you are calling a php function which fails with a timeout before you can throw the exception, your error handling will not work.
Re: try catch with the file function
Posted: Tue Jun 17, 2008 11:12 am
by highjo
i thinks i understand the point.Now its time for alternatives.the application is abuot to send sms on the net and its working as i told you.this part of the application that is giving me the problem is related to giving a delivery status at least 40 seconds after the message has been send with a modal pop up.so i query for the status with the message id by calling the api (this is the very one that show the ) in a loop 5 times.
PS: i have a proper cron job which would do that every 5mn.But for user experience i thought i should give a temporary delivery status after 40 seconds.
That's it.
Need to think differently for that, so i need your suggestion.Thanks for helping