Run Cron Job on PHP Script, on localhost in Windows

前端 未结 4 1191
情书的邮戳
情书的邮戳 2020-11-29 00:32

I have a php script and want to run it on an schedule. I am using local web server on windows (WAMP server) and need a way to run my_script.php every 10

相关标签:
4条回答
  • 2020-11-29 01:20

    To setup a Windows machine to run cron.php at a specific time follow the specific instructions below. This can be useful if you are not familiar with Linux/Unix, or if your web host does not offer the ability to run cron jobs; you can run them remotely from your own computer.

    Note: These instructions were written for Windows XP but should be similar in other versions of Windows.

    https://www.drupal.org/node/31506

    0 讨论(0)
  • 2020-11-29 01:21

    If you use answer from Trix and get same problem as Metafaniel:

    I have a problem, with this procedure, the task is beinge executed, however my php script it's not running, I got the "Open with" dialogue. If I see the properties of my task, it states: ActionName C:\Windows\system32\OpenWith.exe even if I set it to the vbs file as you suggested. What am I doing wrong?

    you should use this:

    1. Instead "enter path to shellscript.vbs like C:\path\to\shellscript.vbs." use "C:\Windows\System32\wscript.exe"
    2. Instead "leave Add argumentts (optional) section empty" use (with quotes): "C:\path\to\shellscript.vbs"
    0 讨论(0)
  • 2020-11-29 01:22

    Little bit late but just for someone who don't want it to be lengthy and don't want to waste time in testing (as the aim is to host it to server), can do one thing by adding http content refresh in the html meta tag of that php file and add the required timer to it and run it in the browser. NOTE: You have to make the system remain open untill you don't get the required output. Again I am saying this is not the perfect and proper way but ya can save someone's configuration setting time.

    0 讨论(0)
  • 2020-11-29 01:27

    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.
    0 讨论(0)
提交回复
热议问题