Running php code on server
Moderator: General Moderators
Running php code on server
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
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
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.martfer wrote:The data is dumped on the server 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
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.
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
oh I forgot to mention, that the graph needs to be updated every minute.
Re: Running php code on server
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.
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
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?
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?
-
kimjonshon0001
- Forum Newbie
- Posts: 1
- Joined: Thu Jan 07, 2010 3:21 am
Re: Running php code on server
Hi Friends,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
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
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
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.
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
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?
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?