views:

103

answers:

3

Please feel free to offer improvements to any of my ideas.

My objective is to have multiple users running a desktop program which will pass information to a php script that will then write the information to a database. No need to worry about the details of the desktop application.

My Questions: 1) Will this method be efficient? Or would it be better for the php script to write the data to a text file and then for a cron job to call a php script to process the text file every minute?

2) When I come out with version 2 of the desktop application, how do I adapt the database to handle the new changes? For example, assume v1 of the program just sends one variable. Then v2 of the program sends two variables. I will not be able to make sure all users upgrade to version 2. So if a user is still using version 1 should the php script just write the one variable data to the database and leave the other variable blank?

Another scenario is that what is in version 2 I decide that the original variable needs to be changed? How do I handle that?

Any comments are appreciated!

+1  A: 

You like to create a rich client. I do not understand what your reasons for php are. If you want to have a client server app I see the following options:

  • The desktop app directly accesses a central database
  • The desktop app communicates with a web service to hide the database details (e.g. versioning )
  • You have php doing all the stuff with the db and use a browser instead of the desktop application.

To handle your second point you should consider using transactions. They guarantee data consistency at every time.

schoetbi
One of the reasons for PHP is that if someone can connect directly to the database, they already have more access than any client should have. Anyone who could find the DB connection string in the app could insert tons of bogus data at will, potentially taking down everything. A PHP script, or some other service running on the server, would make that harder, as the data can more easily be checked and such before it's stored. And for reference, a PHP script can be a web service.
cHao
Yes exactly. The php script just receives the data and give me options to filter the data before adding to the database. It also means I don't have to hard code the database details into the desktop app.
Steve
cHao: Followup question. What address should I use for the database. For example if my webserver was google.com I shouldn't also use google.com for my database address because I wouldn't be able to separate the two later if I wanted my webserver on one computer and my database on another computer, right?So what addresses should I use? google.com for the web server and database.google.com for the database?
Steve
the database does not have an URL. Normally all common databases are being accessed by a so called connection string. What db do you have in mind mysql, postgres, or a fancy NoSql db?
schoetbi
@Steve: The database server's address will be whatever your web host says it is (assuming you don't go with a crappy web host that doesn't include a database in the plan). It doesn't matter what it is, as long as you know it, cause your users should never, ever, *ever* be connecting directly to it in any way.
cHao
+1  A: 

Create a versioned web service API and use that.

Notice the emphisis on versioned.

John MacIntyre
Can you give me a link for further reading?
Steve
I've never read anything on this, so I'm afraid I don't have a link. I just know from experience, that versioning your API is a must.
John MacIntyre
My answer to this question may be helpful to you. http://stackoverflow.com/questions/948355/when-is-an-api-overengineered/948419#948419
John MacIntyre
So this may sound simple but just so I am clear ... I should have www.example.com/v1.php for version 1 of my program and www.example.com/v2.php for version 2? This would create a versioned API? The the php scripts can handle writing to the same database?
Steve
Actually, I would probably do something like www.example.com/api/v1/XXXX.php .... to ... www.example.com/api/vN/XXXX.php. But having said that, maybe you should ask another question about the best way to version a web api. Api's are extremely important, as is versioning, and you don't want to botch it, or you could end up either painted into a corner for the life of your product or with an unusable api.
John MacIntyre
I was thinking about this question when I wrote this: http://twitter.com/JohnMacIntyre/statuses/21333906043
John MacIntyre
A: 

The efficiency of the PHP script will depend on a couple factors, including how well it's written and how your database is structured. Be particularly careful with indexes; they speed up reads quite a bit, but at the cost of slow down writes -- sometimes dramatically.

I'd go with the live updates until i had reason to change it. If things are done right, clients wouldn't notice either way (except for the delay in seeing the data change, if they can even see that).

cHao
I don't have much experience with optimizing databases so I am just going to go with the standard mysql install and use a bunch of tables and keys to keep the data normalized. Then I will learn as I go.
Steve
Watch the keys. They'll be fine for a while, but if you're not careful, at some point you may find MySQL spends more time updating indexes than updating the actual table.
cHao