Connecting Tech Pros Worldwide Help | Site Map

file locking

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 04:19 AM
Bert
Guest
 
Posts: n/a
Default file locking

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







  #2  
Old July 17th, 2005, 04:19 AM
Bert
Guest
 
Posts: n/a
Default 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]



  #3  
Old July 17th, 2005, 04:19 AM
jn
Guest
 
Posts: n/a
Default 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.


  #4  
Old July 17th, 2005, 04:19 AM
Garp
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

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 220,989 network members.