P
P
PO6OT2015-10-04 13:21:50
PHP
PO6OT, 2015-10-04 13:21:50

How to write a semaphore in stock php?

Here's what I found:

<?php 
if ( !function_exists('sem_get') ) { 
    function sem_get($key) { return fopen(__FILE__.'.sem.'.$key, 'w+'); } 
    function sem_acquire($sem_id) { return flock($sem_id, LOCK_EX); } 
    function sem_release($sem_id) { return flock($sem_id, LOCK_UN); } 
} 
?>

But I would like to set max_acquire and make a full-fledged analogue of a semaphore.
I guess I'll have to write the counter data to a file, but I don't know how to get the wait to work properly.
There is an idea to use shared memory as a lockable file instead of a physical file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OnYourLips, 2015-10-04
@OnYourLips

mysqli_query("SELECT GET_LOCK('lockname', 2)");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question