-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamChecker.php
More file actions
63 lines (57 loc) · 1.1 KB
/
Copy pathStreamChecker.php
File metadata and controls
63 lines (57 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Class CheckingAllowRun
*/
class CheckingAllowRun
{
/**
* @var string
*/
protected $filePath;
/**
* @param string $filePath
*/
public function __construct($filePath)
{
$this->filePath = $filePath;
}
/**
* Checks if allow continue work
*
* @return bool
*/
public function allow()
{
@$fp = fopen($this->filePath, 'x+');
if ($fp === false) {
$fp = fopen($this->filePath, 'r');
$time = fread($fp, filesize($this->filePath));
if ($time == '' || (time() - $time) <= 60) {
return false;
}
}
fclose($fp);
return true;
}
/**
* Updates
*/
public function update()
{
@$fp = fopen($this->filePath, 'w+');
if ($fp !== false) {
fseek($fp, 0);
ftruncate($fp, 0);
fwrite($fp, time());
fflush($fp);
fclose($fp);
}
}
/**
* Finishes
*/
public function finish()
{
unlink($this->filePath);
}
}