Heroku scheduler execute a PHP file

后端 未结 2 2180
小蘑菇
小蘑菇 2021-02-19 09:37

i\'m trying to run a php script using the heroku scheduler. What command should i put in after the $ in heroku. I keep getting file not found. I have transferred the file i want

2条回答
  •  温柔的废话
    2021-02-19 09:52

    How to run a PHP script with Heroku Scheduler?

    Testing and setting up the job

    With a directory structure and Procfile looking something like this:

    ├─ Procfile
    ├─ web/
    ├── (your webfiles)
    ├─ worker/
    └── myscript.php
    

    Procfile:

    web: vendor/bin/heroku-php-apache2 web/
    worker: php worker/myscript.php
    

    Then you can test your worker from the command-line like so:

    heroku run worker
    

    To schedule a job, go into Heroku Scheduler and add the job in a similar fashion, but without the heroku run segment (else you'll get bash: heroku: command not found errors), just:

    worker
    

    Or, alternatively, directly:

    php worker/myscript.php
    

    Checking on the job

    You can see the job in the app's logs. e.g.:

    2017-09-01T14:19:37.397210+00:00 heroku[scheduler.9540]: Starting process with command `php worker/myscript.php` 
    

    Notes

    • The worker name in the Procfile could be set to something else. e.g.: myworker, mysuperduperscript, etc.
    • I included a web section, but it's optional if all you want is a worker / background service and don't need to serve files on the web.

    Alternative: if, for whatever reason, you'd rather perform a GET/POST request on a URL, you can use the Temporize Scheduler add-on.

提交回复
热议问题