-1

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

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by network18
1

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

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.