note 124992 added to syncmutex.unlock

From: Date: Sun, 10 May 2020 09:18:31 +0000
Subject: note 124992 added to syncmutex.unlock
Groups: php.notes 
Request: Send a blank email to php-notes+get-214602@lists.php.net to get a copy of this message
If the php process dies unexpectedly (on linux) the lock will remain with no option to remove it. unlock() will not work if the lock is being held by other process. SyncMutex uses shared mem. in that case you can delete the shared memory object in /dev/shm. To list the objects: ls /dev/shm/Sync_Mutex* Keep in mind that objects remain there even after unlocking. So if you use lots of random mutex names then the number of these objects will grow and and you might want to cleanup at some point Example sync.php: <?php $s = new SyncMutex("mymutex"); if(!$s->lock()){ echo "cannot lock\n"; exit; } echo "locked\n"; sleep(10); $s->unlock(); echo "unlocked\n"; ?> then run: php -f sync.php and press ctrl-c. If you run it again it won't lock. So what you can do is: rm -f /dev/shm/Sync_Mutex-*-mymutex Then run it again - it'll lock again ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 176.12.23.237) ---- Manual Page -- http://php.net/manual/en/syncmutex.unlock.php Edit -- https://master.php.net/note/edit/124992 Del: integrated -- https://master.php.net/note/delete/124992/integrated Del: useless -- https://master.php.net/note/delete/124992/useless Del: bad code -- https://master.php.net/note/delete/124992/bad+code Del: spam -- https://master.php.net/note/delete/124992/spam Del: non-english -- https://master.php.net/note/delete/124992/non-english Del: in docs -- https://master.php.net/note/delete/124992/in+docs Del: other reasons-- https://master.php.net/note/delete/124992 Reject -- https://master.php.net/note/reject/124992 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214602) next »