Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP-DB - PHP/MySQL simultaneously running
Old 07-15-2009, 01:27 AM PHP-DB - PHP/MySQL simultaneously running
Junior Talker

Posts: 3
Name: shifany
Trades: 0
Hello I am planning on creating multiple PHP scripts that should constantly be running and I am wondering if PHP scripts can be run at the same time or it waits until another script finishes doing its job

If scripts can run at the same time I have a problem I am curious about

Code:
views = 5

script1.php
loads views from database
views + 1

script2.php
loads views from database
views + 1

script1.php
updates database - views = 6

script2.php
updates database - views = 6

^this should be 7 but can it run at the same time?
__________________

Please login or register to view this content. Registration is FREE

Last edited by shifanyroma; 07-15-2009 at 01:29 AM..
shifanyroma is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-15-2009, 03:54 AM Re: PHP-DB - PHP/MySQL simultaneously running
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Each call on a PHP script is independent of the other scripts you have.
And yes, you can have 2 call that are so close, that the update will be with the same result, although it should not.

This is a known "flaw" caused by the way the display and the request are disconnected in the client/server model the web is built.
The only real way to avoid this, is by using semaphores, or lock.

If you update a db, lock the table you are working with when you update a value.
It will make every other queries against that table to wait for the lock to be released to complete.
That way, you can be sure that only 1 operation can be done in 1 table at a given time.

Otherwise, you can use a "file based" semaphore.
Have both script1 and script2 checking for the existence of a file when they run.
If the file exists, the must wait until the file is gone to work.
But this is less secure than a table lock, as again, 2 request can be so close that they occur at the same time, and both see the semaphore file as not being present.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to PHP-DB - PHP/MySQL simultaneously running
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10734 seconds with 12 queries