Page 1 of 1
Running php code on server
Posted: Thu Jan 07, 2010 2:39 am
by martfer
I'm a bit of a beginner to php and indeed web programming.
I want to know how I can start a php program running on website server. In fact I need how to start and stop it.
The program takes data that is dumped onto the server, and formats the data and places it in a database. The data is dumped on the server every minute.
I plan to write another php program to draw some graphs based on the data in the database.
This raises yet another question about synchronization. What if the program on the server is updating the database at the same time as the database is being accessed by someone over the internet.
Or is there some better way of reading data every minute, formatting it and making this data (3 day history) available over the web?
Thanks in advance,
Martin
Re: Running php code on server
Posted: Thu Jan 07, 2010 2:45 am
by requinix
martfer wrote:The data is dumped on the server every minute.
Meaning new data is available
on the server every minute, right? It's not like you have to go out and get it every minute.
First, I have some questions:
- How much processing do you need to do with the data every minute?
- How often does the graphing need to take place?
- What kind of data? Depending, during the updating process you may need to "offline" the service - which would be bad if it really updates every minute - or you can simply display "old" data.
Re: Running php code on server
Posted: Thu Jan 07, 2010 2:51 am
by martfer
thanks for the prompt response.
The data is basically wind data taken every minute. Wind speed and wind direction.
This data is taken from the hardware (from a post stuck out on beach) and dumped on my website server every minute.
I want save this data in a database, and then to be able to display it in graphical form over the web. I want to display the data over the last 3 days.
Basically there isn't much processing going on, just saving data then producing a graph from the data.
Re: Running php code on server
Posted: Thu Jan 07, 2010 2:52 am
by martfer
oh I forgot to mention, that the graph needs to be updated every minute.
Re: Running php code on server
Posted: Thu Jan 07, 2010 3:08 am
by requinix
FYI: this kind of thing can be tricky to design well.
I would have a daemon of sorts running in the background: PHP, I suppose, but something stabler would be ideal, like a C/C++ program. It "runs" constantly, waking up every minute to do work, and going back to sleep when it's done. Every (eg) 24 hours it dies and gets respawned - as a sort of memory safety measure.
The work would be as you described: dumping data to the database and creating the graph. This graph would be stored as an image (or multiple images) and referenced wherever it was needed.
Done properly, synchronization won't be a problem:
- Depending on what type/amount of data you're storing, you may need a sort of flag or index in the database, telling what records are the most recent and most complete. The daemon would import data first and create the new flag/index last. The simplest scenario would be that the data is simply a row in a table: the INSERT is essentially atomic and so code SELECTing from it will either get the old data or the new data - no fragments of either.
- Depending on what you use to generate the graphs, you may just be able to overwrite the image(s), but worst case would be that they're created in temporary files and then renamed/moved to their final locations.
Re: Running php code on server
Posted: Thu Jan 07, 2010 3:18 am
by martfer
good stuff, I like what I'm hearing. I'm actually a 'c' programmer, I thought I had to write in PHP in order to run on the server.
So my biggest issue right now, is how I go about running a 'c' program on my website server. I tried running 'c' program before as a test and note that the exe was basically copied over to my PC and ran from there. Not on the server as I intended.
I ran the 'c' program by copying it to a directory on my web server and double clicking the icon while accessing the server by the server provider.
What am I doing wrong?
Re: Running php code on server
Posted: Thu Jan 07, 2010 3:36 am
by kimjonshon0001
martfer wrote:I'm a bit of a beginner to php and indeed web programming.
I want to know how I can start a php program running on website server. In fact I need how to start and stop it.
The program takes data that is dumped onto the server, and formats the data and places it in a database. The data is dumped on the server every minute.
I plan to write another php program to draw some graphs based on the data in the database.
This raises yet another question about synchronization. What if the program on the server is updating the database at the same time as the database is being accessed by someone over the internet.
Or is there some better way of reading data every minute, formatting it and making this data (3 day history) available over the web?
Thanks in advance,
Martin
Hi Friends,
In regard to your question if the database is being updated and the same time you try to access the data from it you you get the old data till it is updated. this error is called data redundency.
Get Your Ex Back
Netflix
Re: Running php code on server
Posted: Thu Jan 07, 2010 3:41 am
by martfer
I have no issue displaying old data every now and then. I was wondering if I would get a access denied error, that I need to take into account.
Re: Running php code on server
Posted: Thu Jan 07, 2010 3:44 am
by requinix
The "server" and the "web server" are two different things. You can't run a C program on a web server* but you can run it on the server itself.
Is it running on Unix or Windows?
Unix:
You'll need to compile the program on the server itself using something like gcc. Beyond the scope of this thread and really this entire forum and site.
Windows:
You can probably upload the .exe to the server and run it there. I don't mean "browse to http://server/path/to/file.exe", I mean actually log onto the machine (like with Remote Desktop) and actually run the program.
* Yeah, you can, via CGI. Not talking about that.
Re: Running php code on server
Posted: Thu Jan 07, 2010 3:59 am
by martfer
I guess that's my problem. I don't know the difference between server and web server. What is the difference exactly? I pay a yearly for a web site server, which gives me a web site namely
http://www.martinfernando.com. Under this domain I have a number of directories such as public_ftp, public_html. I copied a 'c' program to a directory under public_hmtl. And ran it. And I noted that it actually ran on my PC. I will try it again just to make sure.
I'm running windows.
The way I see things the program (exe) should run somewhere under my
http://www.martinfernando.com domain. The input data (file) and output database both residing on the server. Is this correct?