Re: starting shell script on server: defer acces when running
| From: | Richard Lynch | Date: | Tue, 06 Jun 2006 23:51:11 +0000 |
| Subject: | Re: starting shell script on server: defer acces when running | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237514@lists.php.net to get a copy of this message | ||
On Tue, June 6, 2006 3:10 pm, Roel Dillen wrote:
> I have a shell script I want to run which generates an html page after
> it
> runs some tests on the software I am writing.
>
> I call the script with exec(
);
>
> The tests take more than 2 minutes to complete.
>
> If I try to run more than one test at the same time: trouble.
>
>
>
> I want to solve this by checking somehow whether the tests are
> running.
>
> If so, then the php code just waits until the running test are
> complete,
> referring the second user to the same results page as the first.
<?php
if (@file_exists("/var/shared/locks/" . __FILE__)){
exit; //already running
}
touch("/var/shared/locks/" . __FILE__);
//rest of script here
unlink("/var/shared/locks/" . __FILE__);
?>
You can also incorporate http://php.net/filemtime to
automatically
remove locks that are older than, say, an hour, so that aborted/killed
scripts don't stay locked up.
--
Like Music?
http://l-i-e.com/artists.htm