session - php code like transaction in database? -



session - php code like transaction in database? -

i have code want run 1 user @ time. don't want create boy complex lock/session relied system, wish delay users request our homecoming message seek again.

the code ssh/powershell connection want isolate it.

it's there handy way that??

i forgot mention it's laravel/php code.

you need acquire "lock" of sort. if there no lock, no 1 accessing anything. if there lock, accessing , rest should wait. easiest way implement using files , acquiring exclusive lock. i'll post illustration class (untested) , illustration usage. can derive working illustration using sample code follows:

class mylockclass { protected $fh = null; protected $file_path = ''; public function __construct($file_path) { $this->file_path = $file_path; } public function acquire() { $handler = $this->getfilehandler(); homecoming flock($handler, lock_ex); } public function release($close = false) { $handler = $this->getfilehandler(); homecoming flock($handler, lock_un); if($close) { fclose($handler); $this->fh = null; } } protected function acquirelock($handler) { homecoming flock($handler, lock_ex); } protected function getfilehandler() { if(is_null($this->fh)) { $this->fh = fopen($this->file_path, 'c'); if($this->fh === false) { throw new \exception(sprintf("unable open specified file: %s", $this->file_path)); } } homecoming $this->fh; } }

usage:

$lock = new mylockclass('/my/file/path'); seek { if($lock->acquire()) { // stuff $lock->release(true); } else { // working, either wait or disconnect user } } catch(\exception $e) { echo "an error occurred!<br />"; echo $e->getmessage(); }

php session laravel

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -