13 private $format =
'Y-m-d H:i:s';
14 private $destruct =
true;
22 public function __construct(
string $id =
'',
int $ttl = 3600) {
23 $this->
id = $id ?: md5(microtime());
24 $this->path = $GLOBALS[
'egotec_conf'][
'tmp_dir'] .
"pid_{$this->id}";
29 $this->
pid = getmypid();
33 'created' => date($this->format),
35 ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
38 register_shutdown_function([$this,
'remove']);
40 $value = $this->read();
42 $this->
pid = $value[
'pid'];
43 $this->destruct =
false;
52 if ($this->destruct) {
62 public function id() : string {
71 public function pid() : int {
80 private function read() : array {
84 $value = json_decode($value,
true);
101 $value = $this->read();
102 if (!empty($value)) {
103 if (function_exists(
'posix_getpgid') && !posix_getpgid($value[
'pid'])) {
106 return date($this->format, strtotime($value[
'created']) + $this->ttl) > date($this->format);
116 public function remove() :
void {
118 @unlink($this->path);
__construct(string $id='', int $ttl=3600)
static file_put_contents($filename, $data, $flags=0, $context=null)
static file_get_contents($filename, $utf8=true, $context=null)