Reputation:
I have a script that sends a mail if a condition is true. In order to run the script I have to visit localhost/index.php. Every time I refresh the webpage the script checks if the condition is true, and if it is, it sends me an email.
How do I make this script run every minute without having to have my browser on refreshing the page every minute?
My current solution is to put this in my PHP file:
<meta http-equiv="refresh" content="60;url=index.php" />
Upvotes: 1
Views: 2011
Reputation: 32360
You can run a PHP script without the browser by to following line put into
Start -> run
c:\program files\xampp\path\to\php\bin\php.exe -f c:\htdocs\script\script.php
Put this into the Windows Task Scheduler run input.
EDIT: As the OP said they were using WAMP, PHP is actually in this folder structure
\wamp\bin\php\phpx.y.z\php.exe
Upvotes: 2
Reputation: 3028
In windows you need Task Scheduler for that.
you need to run php.exe file in some regular interval and that file will execute your php script for example,
C:\Path\to\php.exe -f "C:\Path\to\file.php"
thus, with Windows Task Schedular you can run php.exe file in some regular interval with specified condition. Here are the steps,
1. Open Task Scheduler
2. In Task Scheduler, Click on "Action -> Create Task" from menubar.
3. In "General" tab write "Name"- Name of Task and "Description" - Description for Task
4. In "Triggers" tab click on "New" and give triggering time as per requirement.
5. In "Actions" tab click on "New" and select Action - Start Program (which is Default).
And from browse button select your php.exe file from your php installed files.
And in "argument" give file path with Option ex. -f c:\Path_To_Htdocs\fileName.php
(here -f
is option).
6. In "Conditions" tab you can set condition when to run task means about the your pc status like idle/on AC power, etc. I suggest you to leave it as default.
7. In "Settings" tab you can specify some extra settings. I suggest you to leave it as default.
8. Finally As you done, Click on "Run" from "Action" to run it manually.
Upvotes: 0
Reputation: 219934
Use Windows Task Scheduler. It allows you to run scheduled tasks like Cron for *nix.
update
PHP works from the command line like many other server side languages. This means if parameters are required you can pass them as such:
php C:\Path\to\script\script.php param1 param2
param1
and param2
are passed to your script in a similar way that $_POST
and $_GET
variables are. See PHP command line usage for more details on how this works. But it would mean very little change to your script which is nice.
Upvotes: 4