|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-10-16 16:55 UTC] s dot s at terra dot com dot br
Description:
------------
Should be great if there was an optional parameter (default = 0) in function sem_acquire to pass a timeout (in seconds).
Maybe send a warning no semaphore timeout ;)
Reproduce code:
---------------
Something like
<?php
$key = ftok(__FILE__, 'R');
$sem = sem_get($key);
if(sem_acquire($sem, 10)) {
echo 'Semaphore acquire failed. Timeout?';
}
else {
echo 'Semaphore acquired :)';
sem_release($sem);
}
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
You can do this with pcntl_alarm() and pcntl_signal() to send yourself the SIGALRM POSIX signal after a number of seconds. <?php declare(ticks = 1); function handle_timeout() { throw new Exception('Semaphore acquire timeout'); } pcntl_signal(SIGALRM, 'handle_timeout'); $key = ftok(__FILE__, 'R'); $sem = sem_get($key); pcntl_alarm(10); sem_acquire($sem); pcntl_alarm(0); echo 'Semaphore acquired :)'; sem_release($sem);