Periodically Storing PHP Variable (newbish question)
Moderator: General Moderators
-
Tomcat7194
- Forum Commoner
- Posts: 48
- Joined: Mon Jul 31, 2006 1:34 pm
Periodically Storing PHP Variable (newbish question)
Hello.
I'm just getting started with PHP, and I have a question that probably has a simple answer, but extends beyond my knowledge. I'm working with a PHP script that generates an integer variable based on dynamically changing factors. I want to keep a record of this variable in a MySQL document, so I can chart its changes over time.
I'm assuming that to keep a record of a PHP variable, I'm going to need some kind of server side script that periodically calls my PHP script, processes the variable, and then stores it in MySQL. What language should I use? Where do I put the script on my server? Is there a good tutorial I should read so I can learn how to do this kind of stuff?
Thanks
Tom
I'm just getting started with PHP, and I have a question that probably has a simple answer, but extends beyond my knowledge. I'm working with a PHP script that generates an integer variable based on dynamically changing factors. I want to keep a record of this variable in a MySQL document, so I can chart its changes over time.
I'm assuming that to keep a record of a PHP variable, I'm going to need some kind of server side script that periodically calls my PHP script, processes the variable, and then stores it in MySQL. What language should I use? Where do I put the script on my server? Is there a good tutorial I should read so I can learn how to do this kind of stuff?
Thanks
Tom
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
This should be a very straight forward and easy task. The thing to remember is that every time that var has activity it needs to be documented in the database, so you are going to need to develop a means to account for the var, make it available, update it and process it. It is not hard to do, but there is some logic involved in it.
-
Tomcat7194
- Forum Commoner
- Posts: 48
- Joined: Mon Jul 31, 2006 1:34 pm
I figured I'll use time as the trigger for storing the variable, so that it adds a new entry to the database every 5 minutes or so.
My issue is how to actually go about doing this--can I do something like that with PHP? It seems like I would then have to have the script running all the time, so it would always be monitoring and storing the variable. In order to do this, wouldn't I have to do something server side (or leave a browser open all the time with the script running)? Or can PHP handle that sort of thing on its own?
Tom
My issue is how to actually go about doing this--can I do something like that with PHP? It seems like I would then have to have the script running all the time, so it would always be monitoring and storing the variable. In order to do this, wouldn't I have to do something server side (or leave a browser open all the time with the script running)? Or can PHP handle that sort of thing on its own?
Tom
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
Tomcat7194
- Forum Commoner
- Posts: 48
- Joined: Mon Jul 31, 2006 1:34 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Every now and again you can set up a cron job with your cpanel. Have a look around your control panel and see if there is something in there that can walk you through it. I think basically you tell your server what time to do what and point it at a script and the server will execute it. I think that it how it should work.
-
Tomcat7194
- Forum Commoner
- Posts: 48
- Joined: Mon Jul 31, 2006 1:34 pm
Yeah, I found a Crontab function in Cpanel, and I figured out how to make it send a command at a specified time interval. For the command, I just entered the URL of the script, but that doesn't appear to be working. Do I have to enter some kind of command besides just the URL to get it to run the script?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
Tomcat7194
- Forum Commoner
- Posts: 48
- Joined: Mon Jul 31, 2006 1:34 pm
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA