I have a long running php script that sends out emails and updates the database. The script takes about 45 minutes to complete. I have a progress indicator in which I can see on which iteration of the loop problems could occur. Always after about 12 minutes an error unknown error occurs. There's no problem with the mailing script. It looks to me like the mysql database connection is dropped. Is there a way to extend the duration of the connection? Thanks
Asked
Active
Viewed 341 times
0
-
It can also be that the whole php script is stopped. Your `max_execution_time` setups for php scripts should at least be 2700 seconds, 3000 to be 100% sure. I am not so sure that 45 min php script is a good idea though. There is also mysql `connect_timeout` property which sets the mysql timeout, but as far as i know it is not set by default. – Eugene Anisiutkin Nov 26 '18 at 08:29
-
It's better not to have such long running scripts at all. Consider refactoring your script into a message queue or cron job. – Gino Pane Nov 26 '18 at 08:37
-
@Gino Pane, how would I go about doing this with a cron job? I basicly have a while loop that iterates through 1700 records, sending an email through GMAIL API and then adding a record to the database in which I collect that the message was send alright. – Sven Nov 26 '18 at 09:21
-
Divide your task into chunks and do many small chunks instead of a single long script. – Gino Pane Nov 26 '18 at 09:22
1 Answers
0
I think it's not a problem with mysqli
, but you can look for max_execution_time
in your php.ini file and change it to a suitable value. Here you can read more about this.
But it's better to check your server log to get more insight of your problem.

dilusha_dasanayaka
- 1,401
- 2
- 17
- 30