Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement semaphores in PHP without PHP Semaphore?
    text
    copied!<p><strong>Question:</strong></p> <p>How can I implement shared memory variable in PHP without the semaphore package (<a href="http://php.net/manual/en/function.shm-get-var.php" rel="nofollow">http://php.net/manual/en/function.shm-get-var.php</a>) ?</p> <p><strong>Context</strong></p> <ul> <li>I have a simple web application (actually a plugin for WordPress)</li> <li>this gets a url</li> <li>this then checks the database if that url already exists</li> <li>if not then it goes out and does some operations</li> <li>and then writes the record in the database with the url as unique entry</li> </ul> <p>What happens in reality is that 4,5,6 ... sessions at the same time request the url and I get up to 9 duplicate entries in the database of the url.. (possibly 9 because the processing time and database write of the first entry takes just enough time to let 9 other requests fall through). After that all requests read the correct entry that the record already exists so that is good.</p> <p>Since it is a WordPress plugin there will be many users on all kind of shared hosting platforms with variable compiles/settings of PHP.</p> <p>So I'm looking for a more generic solution. I cant use database or text file writes since these will be too slow. while i write to the db the next session will already have passed.</p> <p>fyi: the database code: <a href="http://plugins.svn.wordpress.org/wp-favicons/trunk/includes/server/plugins/metadata_favicon/inc/class-favicon.php" rel="nofollow">http://plugins.svn.wordpress.org/wp-favicons/trunk/includes/server/plugins/metadata_favicon/inc/class-favicon.php</a></p> <p><strong>update</strong></p> <p>Using a unique key on a new md5 hash of the uri together with try catches around it seems to work.</p> <p>I found 1 duplicate entry with</p> <pre><code>SELECT uri, COUNT( uri ) AS NumOccurrences FROM edl40_21_wpfavicons_1 GROUP BY uri HAVING ( COUNT( uri ) &gt;1 ) LIMIT 0 , 30 </code></pre> <p>So I thought it did not work but this was because they were:</p> <pre><code>http://en.wikipedia.org/wiki/Book_of_the_dead http://en.wikipedia.org/wiki/Book_of_the_Dead </code></pre> <p>(capitals grin)</p>
 

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