Re: fclose() problem
| From: | Peter Lewis | Date: | Fri, 07 Jul 2000 07:06:46 +0000 |
| Subject: | Re: fclose() problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5333@lists.php.net to get a copy of this message | ||
On Fri, 7 Jul 2000, David Robley wrote:
Sorry, I haven't tried the intval yet because I still can't access the
page with the fclose()
IT WORKS with the fclose() commented out.
> On 7 Jul, Peter Lewis wrote:
> > Please excuse my writing to this list if it the wrong one.
> > Let me know and I'll redirect
> >
> >
> > Hello all,
> >
> > I have a major problem with my PHP3 script!
> >
<snip>
> > 1 $name="pcnum.txt";
> > 2 $file=fopen($name,"w");
>
> Oh dear - that's just destroyed the contents of the file. Make that
> $file = fopen(($name,"r");
WHY?? (( since only one closing )
> > 3 $Count=fread($file(filesize($name));
>
> The arguments to fread need to be separated by a comma;
> $Count=fread($file, filesize($name));
>
Done - No joy.
> > $Count is a string value, so need to cast it as integer to do
> incrementing
> $Count = intval($Count);
Will try once the fclose() problem solved.
> So we get
> <?php
> $name="pcnum.txt";
> $file=fopen($name,"r");
> $Count=fread($file, filesize($name));
> $close = fclose($file);
> $Count = intval($Count);
> $Count++; // also used $Count += 1
> $fd=fopen($name,"w");
> fputs($fd,$Count);
> fclose($fd);
> ?>
>
> which works a charm in incrementing the counter but of course, run as
> is, will return Document contains no text.
True oh true - couldn't figure out why when I had a look in the file it
was empty.
> As a further exercise, consider the case where there are multiple
> accesses to the counter script almost simultaneously >:-)
>
I know, I have considered flock() at each access but
a) I haven't got that
far yet and
b) I don't know how. Had planned to read manual at that
stage. :-) (-: [in pairs so they don't get lonely].
>
> Cheers
> --
> David Robley | WEBMASTER & Mail List Admin
> RESEARCH CENTRE FOR INJURY STUDIES |
> http://www.nisu.flinders.edu.au/
> AusEinet |
> http://auseinet.flinders.edu.au/
> Flinders University, ADELAIDE, SOUTH AUSTRALIA
>
>
Let not mercy and truth forsake you: bind them about your neck; write them
upon the table of your heart, so shall you find favour and good understanding
in the sight of God and man.