Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to access/update one table from two or more scripts?
    primarykey
    data
    text
    <p><strong>Background</strong></p> <p>I have a table with data that two or more PHP scripts will access simultaneously. The data looks something like this:</p> <pre><code>+--------+-------------------+-----------+-----------+ | ID | Start | End | Status | +--------+-------------------+-----------+-----------+ | 1 | 1000 | 1500 | 0 | | 2 | 1000 | 1500 | 0 | | 3 | 1000 | 1500 | 0 | | 4 | 1000 | 1500 | 0 | +--------+-------------------+-----------+-----------+ </code></pre> <p>The PHP scripts perform the following query when they start up:</p> <pre><code>SELECT * FROM `table` WHERE `Status` = 0 LIMIT 1 </code></pre> <p>The PHP script then performs a loop from the <code>start</code> value to the <code>end</code> value (1000 to 1500). After its done, it updates the <code>Status</code> of that row to <code>'1'</code>. It automatically redirects to itself and restarts the the whole process.</p> <p><strong>The challenges I have are</strong>:</p> <ol> <li><p>If I want 2 or more of the same PHP script to run simultaneously accessing the same Database, how do I ensure that they're <strong>not</strong> accessing the same record?</p></li> <li><p>The bigger challenge is that if I want to split up the loop from <code>start</code> to <code>end</code> over multiple instances of the same PHP script, i.e., every 100 values is one instance of the script, and after reaching <code>1100</code>, update the MySQL <code>Start</code> to <code>1100</code> and redirect to the same script which starts at <code>1101</code> to <code>1200</code> and so on till the <code>End</code> number is reached. After the <code>End</code> number has been reached, that record's <code>Status</code> will be set to <code>1</code> and it will move on the next record. In the real situation, its for about a million count from start to end, and some memory intensive functions are performed in the loop, so I need to chunk it out.</p></li> </ol> <p>All I know about row-level locking, I learned in the last few minutes; and none of that seems to answer multiple instance locking from one script. </p> <p>Should I consider session IDs/cookies? What do you recommend?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload