| | |
Multiple scripts "same time"
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 68
Reputation:
Solved Threads: 6
Hello,
I'm making a browser based game in php and so far it's going really good.
However I have a doubt about a script i've written.
This script does alot of calculations using the data from the mysql database i'm using. So it reads and writes quite alot. And the script can take up to a second or two to execute.
Now if two players execute the script at the same time and the script uses the same fields in the database for both executed scripts. Will those scripts be executed one after another or at the same time (using multithreading or something)
In short: Do the scripts in PHP get executed in a queue or at the same time.
And the same question for mysql queries.
Thanks in advance,
Tigran
I'm making a browser based game in php and so far it's going really good.
However I have a doubt about a script i've written.
This script does alot of calculations using the data from the mysql database i'm using. So it reads and writes quite alot. And the script can take up to a second or two to execute.
Now if two players execute the script at the same time and the script uses the same fields in the database for both executed scripts. Will those scripts be executed one after another or at the same time (using multithreading or something)
In short: Do the scripts in PHP get executed in a queue or at the same time.
And the same question for mysql queries.
Thanks in advance,
Tigran
•
•
Join Date: Aug 2005
Posts: 150
Reputation:
Solved Threads: 13
Unfortunately, PHP does handle a couple of request parallel. As I don't know exactly what these data are for, I can suppose two ideas for updating the database:
1. Lock it!
Add a new field called "inuse" or "locked" that you mark with 1 before you do all the calculation. At the end of your script you update the coulm and set it back to "0". When the second user executes the script and the column is still marked with "1" the script stops and reloads after one or two seconds.
This possibility does slow your execution down, of course.
2. Make different rows!
When the calculated data is just for player only (no global variables) you can simply add a column to the table that saves an unique ID of the player. Then you can check with each update, that only the row of the player is changed. But this just works, when the data are not important to the next player.
Hope that helped. If not, try to give a more detailed description of your problem.
Greetings
Simon
1. Lock it!
Add a new field called "inuse" or "locked" that you mark with 1 before you do all the calculation. At the end of your script you update the coulm and set it back to "0". When the second user executes the script and the column is still marked with "1" the script stops and reloads after one or two seconds.
This possibility does slow your execution down, of course.
2. Make different rows!
When the calculated data is just for player only (no global variables) you can simply add a column to the table that saves an unique ID of the player. Then you can check with each update, that only the row of the player is changed. But this just works, when the data are not important to the next player.
Hope that helped. If not, try to give a more detailed description of your problem.
Greetings
Simon
•
•
Join Date: Sep 2009
Posts: 551
Reputation:
Solved Threads: 64
The type of table in mySQL will serve a lot of purpose for this 
ex. innodb or myISAM
innodb provides the lock on row basis instead of that on complete table.
So ur this type of problem might get solved, just have some research for the table types of mysql and probably you can change your database/table structure to implement it.

ex. innodb or myISAM
innodb provides the lock on row basis instead of that on complete table.
So ur this type of problem might get solved, just have some research for the table types of mysql and probably you can change your database/table structure to implement it.
![]() |
Similar Threads
- Running multiple scripts at once (JavaScript / DHTML / AJAX)
- c++ Count Down Timer "time.h" (C++)
- google "keyword" question (Search Engine Optimization)
- inputing system("date /t") and system("time /t") into a file (C++)
Other Threads in the PHP Forum
- Previous Thread: Login Case Sensitive Issue
- Next Thread: two databases issue
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube





