Re: About exec() function
| From: | Stas Trefilov | Date: | Wed, 05 Jul 2000 10:46:07 +0000 |
| Subject: | Re: About exec() function | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-874@lists.php.net to get a copy of this message | ||
Zhu bo wrote:
>
> Hi,
> When I run following sample in my php enviroment,my pc will wait for a long time ,maybe the
> problem is in exec( "del $counterFile");
> ,could your tell me right answer?
> The following is this sample.
> <?php
>
> $counterFile = "counter.txt";
> $fp = fopen($counterFile,"rw");
> $a=file_exists($counterFile);
> exec( "del $counterFile");
> function displayCounter($counterFile) {
> $fp = fopen($counterFile,"rw");
> $num = fgets($fp,5);
> $num += 1;
> print "ÄúÊÇµÚ "."$num"." λÎÞÁÄ·Ý×Ó";
> exec( "del $counterFile");
> exec( "echo $num > $counterFile");
> }
>
> if (!file_exists($counterFile)) {
> exec( "echo 0 > $counterFile");
> }
>
> displayCounter($counterFile);
> ?>
Please be kind not to delete opened files!
Use unlink () to delete file.
Use fputs () to write to file.
In your case you don't have to delete file at all, just rewrite it's contents.
See fopen () documentation.
--
Stas Trefilov
Moscow Russia