Use PHP to Set Cron Jobs in Windows

How to setup cron jobs on Windows?

You can't install cPanel on Windows. It's Linux only. Windows uses "Task Scheduler". You might want to check this out: https://support.qualityunit.com/384836-How-to-set-up-cron-job-on-a-Windows-server

PHP cronjob on Windows with parameter and pipe

Try adding -- before the --run like this:

cmd /C C:\php\php.exe "C:\cron\cronrun.php" -- --run >> "C:\cron\log\cronrun.log" 2>&1

The clue is in the usage message:

$ php --help
Usage: php [options] [-f] <file> [--] [args...]

...

args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin

Run Cron Job on PHP Script, on localhost in Windows

recently I had sort of problems to run a cron job on a php script on localhost (WAMP server) in windows 7, when I was on a test to chronically fetch some links from www out there.

By the way I am sharing this for anyone that is on the same thing.

You will need a shellscript to run chronically, using Windows Task Scheduler. Also you will need a batch script (script.bat) to call the php.exe and run your php script (here called as my_process.php)

shellscript.vbs

Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\path\to\script\script.bat" & Chr(34), 0
Set WinScriptHost = Nothing

script.bat

"C:\wamp\bin\php\php5.4.12\php.exe" -f "C:\wamp\www\website\my_process.php"

Now, we are ready to set the Windows Task Scheduler to run shellscript.vbs at the required time interval:

  1. Open Task Scheduler from windows Start menu
  2. Go to Action menu and hit Create Task...
  3. in General tab, fill the Name and Description fields as you want
  4. in Triggers tab, hit New button.
  5. from Begin the Task dropdown, select On a schedule and choose Daily
  6. from Advanced settings section, select Repeat task every as you want and set for a duration on Indefinitely.
  7. on Actions tab, from Action dropdown, select Start a program.
  8. on the Program\script box, enter path to shellscript.vbs like C:\path\to\shellscript.vbs.
  9. leave Add argumentts (optional) section empty.
  10. in Start in (optional) box, enter parent directory of shellscript.vbs like C:\path\to\.
  11. Hit upvote on this tutorial :) Have fun.

Run php file as cron job in windows 8.1 using php.exe

After many hurdles we got the solution of our problem

We have face three problems to make working this.

1). We have change our ActionTab to this

Program / script :- D:\xampp\php\php.exe

Add arguments (optional) :- -c D:\xampp\php\php.ini -f D:\xampp\htdocs\PushNotificationSql\tasknotification.php

Start in (optional):- [Remain empty]

This will successfully call php script from cmd using php.exe

2). In our php script there is code which is called php function from javascript and we knows that script code does not run using cmd its only handle by browser so we have change it and then it works fine.

3). And we have another php file include into this cron php file [tasknotification.php] so we have to write pull path of that included file.



Related Topics



Leave a reply



Submit