9

I'm new to HEROKU APPS.

In my heroku app i have a problem. that is I'm using a php script to save data on server.

Example :

<?PHP

$file = "example.txt";

$data = "Something...";

file_put_contents($file,$data);

?>

This PHP script run successfully and save data perfectly.

But, when I deploy my APP to HEROKU to update -> in this precess example.txt file is automatically deleted.

hakre
  • 193,403
  • 52
  • 435
  • 836
Jooxa
  • 627
  • 3
  • 12
  • 27
  • You didn't ask a questions but you've made a statement. Accept what you experience, because there is nothing to fix. This is the intended behavior and Heroku documentation is clear about that. – hakre Dec 25 '12 at 15:44

3 Answers3

12

Heroku File Systems

Heroku behavior varies depending a little on the stack you use. With Bamboo, most of the file system is read-only. With Cedar, it is ephemeral.

In either case, the file systems are not shared between dynos, and should not be used for storage. To reliably store data server-side, you will need to use the database (perhaps storing your uploads as blobs), or as external assets on another host or service.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
3

Heroku does not supply hard disk space to persistent files between git pushes, you'll have to use something like Amazon S3 for file storage. That is why Heroku calls their filesystem Ephemeral filesystem. It was even read-only in earlier versions of the stack.

Heroku has a tutorial on it: Using AWS S3 to Store Static Assets and File Uploads

hakre
  • 193,403
  • 52
  • 435
  • 836
Femaref
  • 60,705
  • 7
  • 138
  • 176
  • Femaref , `HEROKU` gives 200MB space with free of cost. – Jooxa Dec 25 '12 at 15:49
  • 1
    @user1882503: Yes, for your code. That is what is in your git repro If you commit new files into your tree, that's perfectly fine. If not, they are lost. Easy. – hakre Dec 25 '12 at 15:52
  • @hakre do you know any way to get or retrieve those files before being deleted? Or is it even possible? – Suhail Ahmed Feb 12 '22 at 18:02
  • @Cell No, and this is likely why they worded it "ephemeral". But perhaps support can help you? – hakre Feb 13 '22 at 12:11
  • Oh yeah i did it myself, just hop in heroku bash session & `python manage.py dumpdata > whole.json && cat whole.json`. Not sure about static assets i just had blog posts. – Suhail Ahmed Feb 14 '22 at 10:48
1

Please see the docs:

Ephemeral filesystem

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted.

So you can not save much with your Heroku dyno. Especially after you've pushed your new version, the dyno is restarted and the file-system is reset then.

You need to store files into a remote location then if they should survive the dyno reset.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836