Run PHP script in Windows Task Scheduler
I have a PHP script that I currently leave running with an open browser, with the command below:
<meta HTTP-EQUIV="refresh" CONTENT="1800">
Despite the memory problems that the browser consumes, it was running everything smoothly. Now I need to develop 3 more scripts that will also run from time to time.
Is there any way to run the script via Task Manager?
I did a test with prompt, but did not succeed, as regardless of the script, it always returns a parse error that does not exist.
Parse error: syntax error, unexpected end of file in C:\wamp\www\reservas\Enviar
EmailLembrete.php on line 281
C:\wamp\bin\php\php5.5.12>php c:\wamp\www\reservas\EnviarEmailLembrete.php
Changing to localhost:
C:\wamp\bin\php\php5.5.12>php -f http://localhost/reservas/EnviarEmailLembrete.p
hp
Could not open input file: http://localhost/reservas/EnviarEmailLembrete.php
Code JsFiddle
1 answers
The most common solution is to schedule this way:
c:/caminhocorreto/php -c c:/caminho/para/o/php.ini [ -f ] c:/caminho/para/o/script.php
This way you'll be picking up the right executable and the correct php.ini
for what you want to do.
Documentation of PHP startup parameters:
http://php.net/manual/pt_BR/features.commandline.options.php
The only caution is to understand that since you are not using the web server (Apache, etc), will not work definitions that are in Files .htaccess
and other typical things of the webserver , like variables $_SERVER[]
.
An alternative if the task is more recurrent is to call a PHP with an infinite loop in the system boot (with the same syntax above), but in order not to "choke" the CPU unnecessarily, at the end of each cycle you call the sleep
, which in addition to giving the necessary pause between one execution and another, frees the CPU