Cristian
Cristian

Reputation: 1670

How to execute a PHP long time script on an a apache2 server?

I have a php script that inserts random data in mysql database. (approximative 1 milion rows) Afer the script begins to run on my browser, after a few minutes (ex. 10 min or so) the script stops. (Chrome is giving me "No data recieved")

In my script I have set the followings:

ini_set('display_errors','On');
ini_set('error_reporting',E_ALL);
ini_set('max_execution_time' ,0);
ini_set('set_memory_limit', '10240MB');

For this project I am using the Laravel framework but I don't think it has something to do with it.

Have any ideas?

Upvotes: 0

Views: 83

Answers (2)

Cristian
Cristian

Reputation: 1670

Found the problem. It was from the framework. For best practices I recomend: https://laracasts.com/lessons/eager-loading

Upvotes: 1

thomas.mc.work
thomas.mc.work

Reputation: 6474

It's always a good approach to do such long running jobs via SSH (if you have SSH access to your server). Then you can execute any PHP-Script via php your-script.php. You just to keep two things in mind: you need to bootstrap your framework properly (if the script depends on it), and then there is also a timeout for SSH connections. You can work around this limitation by sending the running job in the background or use the screen command.

Upvotes: 1

Related Questions