Web Hosting Talk







View Full Version : OO PHP and spawning things question


input
02-14-2006, 04:01 AM
Hi folks,

I'm a very proficient PHP programmer that has always stayed away from the OOP side of things, but have always known that sooner or later I'll have to delve into OO PHP.

I've written large PHP projects before w/o using OOP, and I've found maintaining the script to be a nightmare, and I'm pretty sure that if I'd used classes, it would be easier - am I right on that?

Anyway, I'm starting a new large project and already I've hit a crippler. The project is very reliant on MySQL with the databases it will uses running to many 100s thousands rows long in total (single tables run to about 50k rows max).

To start out there is only one table with 38k entries and this is where I've hit a very big problem - All the table rows need to be verified and updated at least once a week with data held in flatfiles. About 1-5% of all rows will be updated. However, even without any updates, just a simple recursive SELECT on all the lines of the flatfile (each line represents a row in a db table) for ONE table takes 50 minutes or so to run (each SELECT is taking about 0.05 or 0.1 seconds to run in the foreach() PHP loop).

So, as the sql commands are not too taxing w/r to memory, I would like the script to spawn a few 1000 queries a time (mysql is set to handle 100k concurrent connections), which should speed the script up quite a lot.
Isn't this what OO PHP can do - spawn objects/classes or something?
If in the foreach() loop I can spawn a fresh SELECT query routine without holding up the script waiting for the sql query to finish, how can I limit the number of queries spawned?

I would very much appreciate any insight!
Cheers
Andy

Froggy
02-14-2006, 04:35 AM
Isn't this what OO PHP can do - spawn objects/classes or something?
If in the foreach() loop I can spawn a fresh SELECT query routine without holding up the script waiting for the sql query to finish, how can I limit the number of queries spawned?


No this is what threads do and php doesn't support them. The interpreter is going to excute the code serially no matter what you do.

input
02-14-2006, 06:12 AM
Ah, I guess Perl is the way to go then, with some embedded PHP...

Burhan
02-14-2006, 07:06 AM
Isn't this what OO PHP can do - spawn objects/classes or something?

Don't know what you mean by 'spawn'. Yes, you can create many objects of the same class (as you can with other OOP languages). You can't create threads though, as this is not something PHP supports.

If in the foreach() loop I can spawn a fresh SELECT query routine without holding up the script waiting for the sql query to finish, how can I limit the number of queries spawned?

You can limit the number of queries on the database end, or actually design a view if its the same query you just need modified. Or, use stored procedures.

My point is, keeping track of this on the PHP end is not going to be practical.

input
02-14-2006, 10:28 AM
Yes, by spawn, I meant threading I guess - during each iteration of a foreach() loop (and there are some 28000 iterations) there is mysql_query("SELECT ...). What I wanted to do was to store the queries and then send out 100 or 1000 queries all at once, or something so that the next iteration of the loop could commence without waiting for the response from mysql.

never mind, I optimised some loops and one stupid thing I missed was a critical mysql column key. Oops. Adding the key speeded up the script from about 40-50 minutes to ehm, 37.8 seconds. Did I say I was proficient? Not!

sasha
02-14-2006, 10:41 AM
never mind, I optimised some loops and one stupid thing I missed was a critical mysql column key. Oops. Adding the key speeded up the script from about 40-50 minutes to ehm, 37.8 seconds. Did I say I was proficient? Not!

Haha, I just started the post saying that you must be doing something wrong and should look at indexes :) and or LIMIT when doing updates