jemz — 2013-09-22T08:53:51-04:00 — #1
Hi, I need your help please,...I am using Swiftmailer in sending email,now what i need is how can i catch this "Fatal error: Maximum execution time of 30 seconds exceeded "...so that i can prompt this to the user.
$transport = Swift_SmtpTransport::newInstance('smtp parameter here')
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setSubject('this is the test')
$failed = $err->getMessage();
ginerjm — 2013-09-22T11:42:41-04:00 — #2
IMHO if you are exceeding 30 seconds of time ( a HUGE amount BTW) then it's not something the user needs to be concerned with - it's the programmer. You've got a loop or something in your code that is not doing what you expect
I'm afraid I am not familiar with the type of syntax you are using in your code, so I can offer no solution, other than to say it's not the user's fault and he/she should never see this happening. You need to figure out why you are getting this error.
qmonkey — 2013-09-22T12:26:44-04:00 — #3
try/catch won't get fatal errors. If it is this section of the code that's causing the issue, the problem likely is that it can't connect to the mail server and it times out. The solution there would be to make sure the firewall is not restricting you, the mail server is running properly, etc.
jemz — 2013-09-22T12:55:47-04:00 — #4
Thank you for the reply..
Maybe this is the cause for my attachment the file size is 196kb file this will always raise to fatal error like i posted above...but if i will attach only 27.7kb,it succeeded send.
Thank you in advance.
michael_morris1 — 2013-09-22T20:38:15-04:00 — #5
You can change the maximum execution time allowed in the PHP.ini settings or using the htaccess file. Also consider using a cli script, which has no maximum execution time restriction (though this will need to be fired from a cron job and is tricky to set up).
ginerjm — 2013-09-22T20:44:41-04:00 — #6
IMHO this is a poor solution to the OP's problem. Thirty seconds of cpu time is not something that anyone should be running. It is a problem, not a "long running task", unless he is calculating planetary orbits or something.
And - if I am not mistaken, the html file upload process occurs before the php script runs, therefore it does not impact the cpu time limit of a script. I could be wrong here tho.
mittineague — 2013-09-23T00:58:00-04:00 — #7
Although throwing more time or memory at a script might work, unless it's running on your localhost and you don't mind waiting (and even then) it's much preferable to fix the problem if you can.
This is especially true if your on a shared host. They aren't likely to be pleased if you start hammering resources.
Then again, if only a minor tweak is needed, it might be OK I suppose.
Are you sure it's the file size? i.e. not doing multiple uploads/sends at the same time.
spacephoenix — 2013-09-23T02:04:22-04:00 — #8
I noticed this when comparing the code from your post with how it is in the documentation:
Change that bit to:
->setFrom(array("$email" => 'John Doe'))
Give it a try once that change is made, did it make any difference to the execution time (better, worse or about the same)?