I have deployed a PHP worker on heroku. I have disabled the web dyno because I don't need it. I can't access the shell of the worker dyno using heroku CLI (heroku ps:exec) (First screenshot below). If I enable the web worker, then I can connect using heroku ps:exec

heroku run bash worked though.

I have another question. In the php worker, I have some codes like file_put_contents() to store some data. In my local development machine, those codes work fine and create the files to store data. But in heroku, I can't see those files if I issue ls command (2nd Screenshot)

enter image description here

enter image description here

  • When you run "heroku ps" in the CLI, what's the result? – Shane Steinfeld Sep 30 '18 at 20:50
  • === worker (Free): php bot.php (1) worker.1: up 2018/10/01 01:15:55 +0530 (~ 1h ago) – Sourav Ghosh Sep 30 '18 at 20:55
  • It seems that heroku ps:exec should not be used to open a shell. the actual command is heroku run bash. The second one is working fine. Maybe some online article misguided me. Can you please help with my second questtion? Thanks :) @ShaneSteinfeld – Sourav Ghosh Sep 30 '18 at 20:57
  • I wish I could! I haven't used Heroku very much (yet) :( There's an ongoing discussion about whether people who need help with Heroku would be better served by the StackOverflow community. Some say it's geared more for these types of questions. I agree (at least for the moment). I'd keep your question posted here, but you may want to check out StackOverflow as well: stackoverflow.com/questions/tagged/heroku – Shane Steinfeld Sep 30 '18 at 21:06

heroku run bash will run the bash command on a new instance of your app. ps:exec will connect to a running process. You can read more about the latter here: https://devcenter.heroku.com/articles/exec

file_put_contents() to store some data.

It's best to avoid writing to disk on Heroku as it has an ephemeral filesystem which will be erased upon restart. Data should be stored in an another manner -- either in a storage mechanism like Redis or Postgres, or something like Amazon's S3. You can read more about ephemeral filesystem here: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem

  • ----1. I know that it uses the ephemeral filesystem. I need to store some data during runtime. I don't need them permanently or after a restart. Is there any way to do so?----then why ps:exec can't connect to my worker process? It only connects to my web process if that dyno is running. – Sourav Ghosh Oct 1 '18 at 6:03
  • Got it. heroku ps:exec -a appname --dyno=worker.1. From the documentation "By default, Heroku Exec connects to your web.1 dyno, but you can optionally specify a dyno". My web dyno was off, thus, only using ps:exec without parameters was failing. Now I can the the files (which were created by the worker dyno) also – Sourav Ghosh Oct 1 '18 at 6:22

From the documentation:

By default, Heroku Exec connects to your web.1 dyno, but you can optionally specify a dyno.

So, using heroku ps:exec -a appname --dyno=worker.1 worked fine. To get the dyno name one can use heroku ps:exec --status -a appname or simply heroku ps

Now, heroku run bash creates a one-off-dyno which don't share data with the worker dyno. That's why I was unable see the files created during runtime by the worker. After using ps:exec on the worker dyno, I finally could see those files.

Hope this helps somebody. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.