file locking

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bert

    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.ph p 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\wwwr oot\phptest\PRO CESSORDER.PHP on line 56

    Any advice of where I might find information on why I get this message will
    be appreciated.

    Bert






  • Bert

    #2
    Re: file locking

    Sorry, the error occured on the first call to flock as indicated below.


    "Bert" <bert_remove@me ckcom.net> wrote in message
    news:C417c.1015 7$_Q5.2458@fe07 .usenetserver.c om...[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.ph p 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\wwwr oot\phptest\PRO CESSORDER.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]



    Comment

    • jn

      #3
      Re: file locking

      "Bert" <bert_remove@me ckcom.net> wrote in message
      news:C417c.1015 7$_Q5.2458@fe07 .usenetserver.c om...[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.ph p 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\wwwr oot\phptest\PRO CESSORDER.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.


      Comment

      • Garp

        #4
        Re: file locking


        "jn" <usenet*spamist ehsuckremovetor eply*@jasonnorr is.net> wrote in message
        news:R%27c.3133 85$Po1.133999@t wister.tampabay .rr.com...[color=blue]
        > "Bert" <bert_remove@me ckcom.net> wrote in message
        > news:C417c.1015 7$_Q5.2458@fe07 .usenetserver.c om...[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.ph p 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\wwwr oot\phptest\PRO CESSORDER.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


        Comment

        Working...