Skip to content

Commit e9a4821

Browse files
committed
Updated Readme and FileLocker.
1 parent f862c22 commit e9a4821

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,17 @@ Available commands:
5656
As shown in `config/autoload/cli.global.php`, dot-cli includes a demo command `demo-command` that will help you understand the basics of creating a new command.
5757
For more information, see [laminas-cli documentation](https://docs.laminas.dev/laminas-cli/).
5858

59+
### Setting up as cronjob
60+
```text
61+
* * * * * /opt/plesk/php/7.4/bin/php /var/www/vhosts/example.com/httpdocs/bin/cli.php demo-command -q
62+
```
63+
or
64+
```text
65+
* * * * * cd /var/www/vhosts/example.com/httpdocs/bin && /opt/plesk/php/7.4/bin/php ./cli.php demo-command -q
66+
```
67+
Adapt the command to your secifications by replacing _7.4_ with your PHP version and _example.com_ with your domain name.
68+
69+
Note the **-q** (or **--quiet**) option at the end of the command - it serves as a flag to inform the Application that no output should be returned (unless it's an error).
70+
5971
## License
6072
MIT

src/FileLocker.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ public function lock(): void
109109

110110
$lockFile = $this->getLockFilePath();
111111
$fp = fopen($lockFile, 'w+');
112-
if (!flock($fp, LOCK_EX)) {
113-
throw new Exception('Another process holds the lock!');
112+
if (!flock($fp, LOCK_EX|LOCK_NB, $wouldBlock)) {
113+
if ($wouldBlock) {
114+
throw new Exception('Another process holds the lock!');
115+
}
114116
}
115117
fclose($fp);
116118
}

0 commit comments

Comments
 (0)