问题
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.
回答1:
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.
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/14031971/heroku-deploy-deletes-server-files-automatically