Multiple scripts "same time"

Thread Solved

Join Date: Jun 2008
Posts: 68
Reputation: Tigran is an unknown quantity at this point 
Solved Threads: 6
Tigran Tigran is offline Offline
Junior Poster in Training

Multiple scripts "same time"

 
-1
  #1
Oct 3rd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 150
Reputation: sDJh is an unknown quantity at this point 
Solved Threads: 13
sDJh sDJh is offline Offline
Junior Poster

Re: Multiple scripts "same time"

 
1
  #2
Oct 3rd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 68
Reputation: Tigran is an unknown quantity at this point 
Solved Threads: 6
Tigran Tigran is offline Offline
Junior Poster in Training

Re: Multiple scripts "same time"

 
0
  #3
Oct 3rd, 2009
Thanks, I think that solution 1 might help me.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 551
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro

Re: Multiple scripts "same time"

 
0
  #4
Oct 5th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC