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 to run to heroku but not luck with running it with the scheduler.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
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
:Then you can test your worker from the command-line like so:
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 getbash: heroku: command not found
errors), just:Or, alternatively, directly:
Checking on the job
You can see the job in the app's logs. e.g.:
Notes
worker
name in theProcfile
could be set to something else. e.g.:myworker
,mysuperduperscript
, etc.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.
The default PHP buildpack on Heroku does not currently have PHP CLI support, so you can only use it to serve web requests via Apache and not for scripts in worker dynos. However, this is possible if you are using a PHP buildpack that does have CLI support.
To test it out, I forked the PHP buildpack, switched out the PHP binary with one that was compiled with CLI support, and put together small demo of running a scheduled PHP job on Heroku. See the project's readme for step-by-step instructions. To use this fork on an existing app, set the buildpack with:
Note, the
release
script in my fork sets up thePATH
to resolve thephp
executable in/app/bin/php
with justphp
, unlike the default buildpack that woud require using the absolute path.