0

I have a small PHP app in Cloud9 and I hosted it at Heroku using the Git terminal of Cloud9.

The point of the web app is that there are some configuration values (essentially name value pairs) which an administrator can set in the web app. These values are then stored in a .json file. The web app offers those configuration values stored in that .json through a Rest API and from my Android app, I use the Volley library to consume this API, and get those configuration values in the Android app.

When I change a configuration value through the user interface in the web app, the change IS reflected when I access the REST API through the URL in the browser. When I consume the REST API from my Android app, the change is reflected there too. This change is reflected correctly no matter how many times I run the Android app (which consumes the REST API through Volley) in this session.

BUT The problem is that if I turn off my computer and return to it, say, a couple hours later, the configuration data seems to be set back to initial values again. I checked it many times in the browser (by accessing through URL in browser) as well as in my Android app which is consuming the REST API; the value which I had changed in the web app gives its initial value again.

Any ideas about why this is happening and what I can do about it?


EDIT:

Problem installing MLab MongoDB at Heroku:

enter image description here

Solace
  • 8,612
  • 22
  • 95
  • 183

1 Answers1

1

Could you confirm where you are currently storing your .json file? If you are using the filesystem you'll have this problem as Heroku uses something it calls an ephemeral filesystem. Each dyno gets its own filesystem that exists only as long as that dyno is running. Any changes will be reset whenever your dyno restarts. This happens whenever there is a deployment or once a day. If this is a free dyno it may occur each time it sleeps/wakes but I can't confirm this.

If you are storing values that can change during the lifetime of your application you will need to use non filesystem storage. Heroku has several add-ons that you can experiment with for free. The first ones that spring to mind are mlab or redis.

https://elements.heroku.com/addons/mongolab
https://elements.heroku.com/addons/rediscloud

You can read more about the file system here

Matthew Salt
  • 125
  • 6
  • Yeah I am using the File system. =( – Solace Jun 20 '16 at 08:42
  • 1
    Ah, that explains it then. You could try the memcache add-on. https://elements.heroku.com/addons/memcachedcloud. – Matthew Salt Jun 20 '16 at 10:02
  • OK I don't understand most of the article about filesystem and dynos. Since I am not familiar with Linux, I didn't even undertand what a dyno is, and I am assuming it is a container containing my application.By using the file system, all I meant was that the .json file is one file among all the other .php and .js files of the application project. – Solace Jun 20 '16 at 17:18
  • 1
    A Heroku release is a combination of your compiled code + dependencies which is called a 'slug' and your heroku config. A dyno is a essentially a mini unbuntu box that your release runs on. Whenever a dyno (ubuntu box) restarts you release is reinstalled. Therefore any changes you made to any of your files will be reset to whatever the release contained. That is why you are losing your changes. You need to store this information outside of the dyno itself so memcache or mongo would be a good start. – Matthew Salt Jun 20 '16 at 18:47
  • Thank you very much, I have started learning about MongoDB. But won't MongoDB also be a part of my slug? Won't I lose the changes I make to the database dynamically as well? – Solace Jun 20 '16 at 20:43
  • 1
    Not at all, you can provision a mongo add on from various sources. mLab is the one I have used in the past. They host your mongo database on their cloud infrastructure so you are accessing it remotely from your application. You will of course have the mongo dependency for your php application in your slug but the data will be on the cloud servers. – Matthew Salt Jun 20 '16 at 20:48
  • Thank you so, so much for your help. I have started learning about MongoDB. – Solace Jun 20 '16 at 21:05
  • Hi again. I replaced the file system usage with MongoDB usage in a copy of my app in my local XAMPP server. Then i went ahead to try installing MLab MongoDB plugin at Heroku. But it asks me to enter credit card information for some verification (posting a screenshot in the question) although I have chosen to install the Free Sandbox. I don't even have a credit card. What should I do? I'll be thankful for any suggestions. – Solace Jun 22 '16 at 12:42
  • 1
    Some addons require you to use a heroku verified account, this also has the effect of increasing your free dyno hours from 550/month to 1000/month. They wont actually charge anything to your card. Do you have a debit card? Alternatively you might be able to use a modulus.io account from your heroku app although I haven't tried that. https://devcenter.heroku.com/articles/free-dyno-hours – Matthew Salt Jun 22 '16 at 14:46
  • I have a debit card but I live in Pakistan. I don't think it will work with Heroku. =( – Solace Jun 22 '16 at 19:05