This question already has answers here:
php execute a background process
(21 answers)
Closed 4 years ago.
I need to create a script in php, its created but I need that script run in background because take a 30 minutes procesing diferent files. How can create it, I need run in background and the user can navigate across the site and the script keep running. I try calling the script from ajax async funcition but when change the page of the site the script breaks.
PHP exec("php script.php") can do it.
Related
This question already has answers here:
Asynchronous shell exec in PHP
(14 answers)
Closed 5 years ago.
on my site i try to fire and forget with php:
this line starts a process about 20 seconds:
exec('wget -qO- url-to-process' > /dev/null &');
All script is loaded , without attending this line.
Now my page is fully loaded.
But I have a
DataTable, populated with
an ajax request. The question is
why ajax request doesn't start until that 20 seconds?
What could be the problem?
Do you have a chance to use network tools in the browser and see what runs at what point? Why don't you add logging the microtime of each of the calls and see what comes out of it?
This question already has answers here:
How can I make my PHP script run at a certain time everyday? [duplicate]
(8 answers)
Closed 5 years ago.
I have to send emails automatically on weekend basis by checking database values without form submission or button using codeigniter.is there any idea. someone please help
PHP call with CRON
If what you want is run a php script (that send emails or do what ever you want) automatically, use CRON on your server (if you are on Linux of course) by editing crontab with this command :
crontab -e
Add this line in the end of the file and save it :
0 8 * * 0 /usr/bin/php /home/toto/test.php
This example execute the script test.php in toto home directory every sunday at 8 AM.
More info on how to use cron here : Execute PHP script in cron job
PHP call from MySQL Trigger
There is another way to call a PHP script automatically every sunday or when ever you want, by creating a Trigger on MySQL. Especially if you can't use CRON, on Windows for example (WAMPP). You will use the sys_eval commande in your Trigger procedure.
sys_eval("C:/xampp/php/php.exe -f "C:/xampp/htdocs/phpFile.php");
Here is a good example for this solution : https://stackoverflow.com/a/2763238/2282880
Note : On Windows Server, you could use scheduled tasks to ru the php.exe app too. But never tried.
This question already has answers here:
How to run the PHP script at scheduled time
(4 answers)
Closed 9 years ago.
Is there a way to perform timed events using php from server such that if for example time is 24:00 delete value in mysql database etc.
Technically yes, by creating a never ending loop that checks the time, but you REALLY do not want to do this. If you are using linux you should set up a cron job to run a PHP script
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
php exec() function and different hosts
I have a web app that when save button is clicked it makes an ajax call to save.php. I want to be able to make a command line call for a command line only php script to run from inside of the save.php file.
ex.
some code to make a db call and update db
exec('PathToPHP /path/to/file/refresh.php');
I have tried this and it does not work.
does anyone have a good solution?
thanks
If this process takes a long time and the client doesn't wait for it to finish and navigates away while this is running apache will kill the thread handling this. That I'm sure of. Haven't tested this under fastcgi mode under nginx but I'm pretty sure this will be the case too.
This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
php in background exec() function
After a certain script runs on website I want to do a bit of processing in the background which could take a little long to run on the page request.
I heard you can do this by using the exec() method to run a PHP script.
If this is a good way to do it how do I pass a query string to PHP script with the exec() method?
EDIT:
It's not a duplicate because the post you're referring to doesn't deal with my question about query string/argument passing.
If you want to run a PHP script in the background using PHP, then you can do the following:
$command = "php -d max_execution_time=50 -f myfile.php '".$param."' >/dev/null &";
exec($command);
$param is a variable you want to pass into the file.
Since your script runs in the background and not in a terminal, try ignore_user_abort( TRUE ); execution flow continues until execution is complete, and not when the tab or window or network connection is closed.