I have a php function to save multiple rows in database, I can't use this on the web requests since it takes much time. In the function, first I need to obtain a list of ids from database, do some processing, then save new set data into another table. Is it possible to run this script from php, for example from a controller?
1 Answer
Use shell_exec
$output = shell_exec('php YourFile.php');
OR
exec
exec('php YourFile.php')
OR
cronjob ( As @Thomas mentioned )
* * * * * php /var/www/file.php >> /var/www/log/cron.log 2>&1
If you want to run it continuously set_time_limit(0)
<?php
set_time_limit(0);
3 Comments
Thomas
Problem is this will block until it finishes, better to use a cron so it doesn't block.
exec('php other_script.php')set_time_limit()for anyone else who wasn't aware. php.net/manual/en/function.set-time-limit.php