file locking 
July 17th, 2005, 05:19 AM
| | | |
I am new to php and am on chapter 2 PHP and MySQL by Welling and Thomson.
When executing the code from the example to write the output data string:
// open file for appending
@ $fp = fopen("../../orders/orders.txt", "a");
flock($fp, 2);
if (!$fp)
{
echo "<p><strong> Your order could not be processed at this time. "
."Please try again later.</strong></p></body></html>";
exit;
}
fwrite($fp, $outputstring);
flock($fp, 3); //line 56
fclose($fp);
The processorder.php page opens and the screen output is ok. Then I get the
following message below the order echos:
Warning: flock(): supplied argument is not a valid stream resource in
c:\inetpub\wwwroot\phptest\PROCESSORDER.PHP on line 56
Any advice of where I might find information on why I get this message will
be appreciated.
Bert | 
July 17th, 2005, 05:19 AM
| | | | re: file locking
Sorry, the error occured on the first call to flock as indicated below.
"Bert" <bert_remove@meckcom.net> wrote in message
news:C417c.10157$_Q5.2458@fe07.usenetserver.com...[color=blue]
> I am new to php and am on chapter 2 PHP and MySQL by Welling and Thomson.
>
> When executing the code from the example to write the output data string:
>
> // open file for appending
> @ $fp = fopen("../../orders/orders.txt", "a");
>
> flock($fp, 2);
>
> if (!$fp) //line 56
> {
> echo "<p><strong> Your order could not be processed at this time. "
> ."Please try again later.</strong></p></body></html>";
> exit;
> }
>
> fwrite($fp, $outputstring);
> flock($fp, 3);
> fclose($fp);
>
> The processorder.php page opens and the screen output is ok. Then I get[/color]
the[color=blue]
> following message below the order echos:
>
> Warning: flock(): supplied argument is not a valid stream resource in
> c:\inetpub\wwwroot\phptest\PROCESSORDER.PHP on line 56
>
> Any advice of where I might find information on why I get this message[/color]
will[color=blue]
> be appreciated.
>
> Bert
>
>
>
>
>
>[/color] | 
July 17th, 2005, 05:19 AM
| | | | re: file locking
"Bert" <bert_remove@meckcom.net> wrote in message
news:C417c.10157$_Q5.2458@fe07.usenetserver.com...[color=blue]
> I am new to php and am on chapter 2 PHP and MySQL by Welling and Thomson.
>
> When executing the code from the example to write the output data string:
>
> // open file for appending
> @ $fp = fopen("../../orders/orders.txt", "a");
>
> flock($fp, 2);
>
> if (!$fp)
> {
> echo "<p><strong> Your order could not be processed at this time. "
> ."Please try again later.</strong></p></body></html>";
> exit;
> }
>
> fwrite($fp, $outputstring);
> flock($fp, 3); //line 56
> fclose($fp);
>
> The processorder.php page opens and the screen output is ok. Then I get[/color]
the[color=blue]
> following message below the order echos:
>
> Warning: flock(): supplied argument is not a valid stream resource in
> c:\inetpub\wwwroot\phptest\PROCESSORDER.PHP on line 56
>
> Any advice of where I might find information on why I get this message[/color]
will[color=blue]
> be appreciated.
>
> Bert
>[/color]
That error means the file couldn't be opened.
Put that flock() after your if(!$fp) block, and you will probably see your
custom error message. | 
July 17th, 2005, 05:19 AM
| | | | re: file locking
"jn" <usenet*spamistehsuckremovetoreply*@jasonnorris.ne t> wrote in message
news:R%27c.313385$Po1.133999@twister.tampabay.rr.c om...[color=blue]
> "Bert" <bert_remove@meckcom.net> wrote in message
> news:C417c.10157$_Q5.2458@fe07.usenetserver.com...[color=green]
> > I am new to php and am on chapter 2 PHP and MySQL by Welling and[/color][/color]
Thomson.[color=blue][color=green]
> >[/color]
>
> When executing the code from the example to write the output data string:
>
> // open file for appending
> @ $fp = fopen("../../orders/orders.txt", "a");[/color]
<snip>[color=blue][color=green]
> > The processorder.php page opens and the screen output is ok. Then I get[/color]
> the[color=green]
> > following message below the order echos:
> >
> > Warning: flock(): supplied argument is not a valid stream resource in
> > c:\inetpub\wwwroot\phptest\PROCESSORDER.PHP on line 56
> >
> > Any advice of where I might find information on why I get this message[/color]
> will[color=green]
> > be appreciated.
> >
> > Bert
> >[/color]
>
> That error means the file couldn't be opened.
>
> Put that flock() after your if(!$fp) block, and you will probably see your
> custom error message.
>
>[/color]
You're using a relative path, so you might like to check where you are - you
might be surprised. Also check file/directory permissions - your web server
account needs to be able to access the file.
Garp |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|