10

I'm using Heroku running a PHP app, I need to setup background workers which talk to external APIs and write to my DB, Heroku has lots of info about setting up workers for Ruby but not for PHP.

Is this easily doable on Heroku with PHP?

I've never tackled launching background processes and I can't seem to find any docs detailing it...

1 Answer 1

14

Add the following environment variables:

# Add this config
$ heroku config:add LD_LIBRARY_PATH=/app/php/ext:/app/apache/lib

Then you can just add the worker to your Procfile.

worker: cd ~/www/ && ~/php/bin/php worker.php
Sign up to request clarification or add additional context in comments.

7 Comments

No joy, I see that the worker process crashes on startup, why is the config var necessary ? Looking at ruby proc files I see examples like "worker: bundle exec stalk worker.php", should it follow a pattern like that?
@cal If you run heroku run bash, and try to run ~/php/bin/php -i, you'll see why the LD_LIBRARY_PATH env variable is needed: /app/php/bin/php: error while loading shared libraries: libmcrypt.so.4: cannot open shared object file: No such file or directory
BTW, I have the same problem as you @cal, but I'm pretty sure the above answer is correct. I tried it with a test.php script that simply <?php echo "123"; ?>, and it does echo 123 then exits. Not sure why my PHP script that runs fine on my own server will just exit with a status code 0 on the Heroku server.
Just making sure, but you have a web process too right? Heroku expects one of your processes to bind to port 80. The following is how to start the apache process in the php buildpack. web: sh boot.sh
This is an immensely useful tip. Works for me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.