Running a php script with a .bat file

后端 未结 6 1459
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 20:49

I need to run a php script at midnight every night on my server. On a linux system I\'d set up a cron job, but I\'m stuck with a windows system.

I know I have to set

相关标签:
6条回答
  • 2021-01-17 21:12

    Sadly this took close to 10 hours to figure out. Some protocols such as WinRM and PSEXEC must pass the logged in user account regardless of the credentials supplied (that or PHP overrides whatever you type in). At any rate, to get PSEXEC, WinRM or just kicking off batch files that connect to remote computers, you will need to change the IIS run as account to a user with rights to those resources (service account). I realize this is a huge security hole, but that is by design. PHP is secure so that it can't be hacked easily, you have to override their security by specifying a run as account. Not the same thing as your app pool account - although your IIS credentials can use your app pool account.

    0 讨论(0)
  • 2021-01-17 21:20

    How about this?

    set php="C:\Program Files (x86)\PHP\v5.3\php.exe"
    %php% -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php
    
    0 讨论(0)
  • 2021-01-17 21:26

    Actually, you don't even need a batch-file. You can run the php-script from the task scheduler.

    Just let the task scheduler run php.exe and set the location of the php-file as the argument of the task.

    0 讨论(0)
  • 2021-01-17 21:26

    Try like this guys!

    cd E:\xampp\htdocs\my-project
    E:
    php artisan schedule:run
    
    0 讨论(0)
  • 2021-01-17 21:36

    Can I suggest a small change.

    echo off
    REM This adds the folder containing php.exe to the path
    PATH=%PATH%;C:\Program Files (x86)\PHP\v5.3
    
    REM Change Directory to the folder containing your script
    CD C:\inetpub\wwwroot\sitename\crons
    
    REM Execute
    php reminder-email.php
    

    PS. Putting Apache,MySQL or PHP in Program Files is a bad idea. Dont use windows folders with spaces in their names.

    0 讨论(0)
  • 2021-01-17 21:38

    The START command optionally accepts a title for the created window as its first argument; in this case, it thinks that C:\Program Files (x86)\PHP\v5.3\php.exe is the title to display and -f (the second argument) is the executable you want to run.

    You can therefore fix this by providing a placeholder title, e.g.

    start "email reminder task" "C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php
    

    Or, preferably, you can ditch the START command altogether (you aren't using any of its unique facilities) and just run PHP directly:

    "C:\Program Files (x86)\PHP\v5.3\php.exe" -f C:\inetpub\wwwroot\sitename\crons\reminder-email.php
    
    0 讨论(0)
提交回复
热议问题