Req #39168 [Fbk->Opn]: Semaphore acquire timeout

From: Date: Mon, 18 Jun 2018 13:18:31 +0000
Subject: Req #39168 [Fbk->Opn]: Semaphore acquire timeout
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215774@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=39168&edit=1 ID: 39168 Updated by: cmb@php.net Reported by: s dot s at terra dot com dot br Summary: Semaphore acquire timeout -Status: Feedback +Status: Open Type: Feature/Change Request Package: Semaphore related Operating System: Freebsd 6 PHP Version: 5.1.6 -Assigned To: cmb +Assigned To: Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2018-06-18 13:13:07] dnt at gmx dot gom @jhill9693: The suggested workaround with pcntl_alarm doesn't work; probably because of #49340 (https://bugs.php.net/bug.php?id=49340). @cmb: $nowait would stop trying to acquire the semaphore immediately. In my case I want to wait for the semaphore a few seconds and fail if it couldn't be acquired. To repeatedly call sem_acquire with $nowait until the semaphore is either acquired or a specified time period is elapsed would be not a good solution. ------------------------------------------------------------------------ [2018-05-05 11:04:34] cmb@php.net As of PHP 5.6.1 the $nowait parameter is available, which appears to provide an even more flexible solution to the timeout problem. Do you agree? ------------------------------------------------------------------------ [2012-12-09 05:16:04] jhill9693 at gmail dot com 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); ------------------------------------------------------------------------ [2006-10-16 16:55:21] 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); } ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=39168&edit=1

« previous php.bugs (#215774) next »