A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: 3 liner PHP crashing my apache.. :(

  1. #1
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    Hi..

    I have this php script that, i think, is causing apache to crash..

    <?
    $file = fopen("entries/entry.txt", 'r');
    passthru($file);
    echo "DENDEN And the new Data is....$newData";
    ?>

    it's such a simple script.. (i was trying to achieve something), but everytime i run it, apache crashes.. i tried other scripts.. they're ok, but this one crashes just keeps crashing apache.. i dont get it..
    Im running foxserv 2.11 BTW..
    I thought it was a corrupt file or something.. so i reinstalled everything.. and the same thing happens..

    please help

    Tea
    [Edited by Tea_J on 08-11-2002 at 11:29 AM]

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    try fpassthru instead
    What did you want to achieve with the $newData part?

    Musicman

  3. #3
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    Originally posted by Musicman
    Hi,

    try fpassthru instead
    What did you want to achieve with the $newData part?

    Musicman
    Oh yeah.. typo on the "f"... how stupid of me..

    but, i wonder why such as simple error crashed my apache webserver (Bundled with FOxServ 2.11) - and the scary part is, if this is a bug in Apache, would this crash a webhosting comp??! ANyone else wana try this?

    Umm, this script is kinda related to my previous post here which you replied to MusicMan, regarding using variabes in a txt file for manipulation in the PHP script..

    I was experimenting on this, trying to get the variables in the txt file $newData to in PHP..

    txt file has:
    name=Tea J&newData=wake Up!!!!!&

    <?
    //open and read the txt file//
    $file = fopen("entries/entry.txt", 'r');

    //pass it to the browzer//
    fpassthru($file);

    // USE ONE OF THE VARIABLES TO for ECHOing ($newData)//
    echo "<br> And the new Data is....$newData";

    ?>


    well, sadly it printed out this..

    name=Tea J&newData=wake Up!!!!!&
    And the new Data is....

    --passthru is ok, but this just proved that the values i read in the txt is recognized in the script... i so need a way to get those txt variables in php as if it was sent via POST METHOD..


  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    do you know the old perl idiom of getting data out of the request into the cgi in the first place?
    Just trying to mimick that

    Code:
    $pairs = explode('&', $data);
    foreach($pairs as $pair)
    {	list($key, $value) = explode($pair, "=", 2);
    	$DATA[$key] = urldecode($value);
    }
    BTW - trying passthru instead of fpassthru on a linux system simply outputs nothing for the passthru part - not even a warning - but sends following output.
    You should perhaps report this as a bug with both php and apache ... and maybe this kind of quirks is one of the reasons why webhosting companies dont use too many wndows servers

    Musicman

  5. #5
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    hmm.. could you explain a tad bit?

    here's what i came up with:

    in txt file(entry1.txt):
    name=Tea J&msg=WAKEY WAKEY!&

    SCriPt:
    <?
    $file = fopen("entries/entry1.txt", 'r');
    fpassthru($file);

    //your code with "$file" as $data (this right?)//

    $pairs = explode('&', $file);
    foreach($pairs as $pair)
    { list($key, $value) = explode($pair, "=", 2);
    $DATA[$key] = urldecode($value);
    }

    echo "<br>And the new Data is....$name";
    ?>


    OUTPUT:
    name=Tea J&msg=WAKEY WAKEY!
    And the new Data is....


    -the $name var in the txt wasnt recognized still. it should have outputed:
    And the new Data is.... Tea J


    PS
    Geesh man, dont ya ever sleep? Coz im from the Phils( i know it's almost a 12 hour differential from most of you guys), and it seems that you reply to my posts whether it's midnight here or AFTERNOON! cool.


  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    $file = fopen("....", "r");
    $data = fread($file, 100000);

    fpassthru does not mix too well with that, you would have to reopen the file or at least fseek after doing the fpassthru

    Musicman

  7. #7
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    umm.. dude... it just wont work..

    <?

    $file = fopen("file.txt", "r");
    $data = fread($file, 1000);

    $pairs = explode('&', $data);
    foreach($pairs as $pair)
    { list($key, $value) = explode($pair, "=", 2);
    $DATA[$key] = urldecode($value);
    }

    echo "And the new Data is....$name";
    ?>


    note: $name is in the txt file


    displays:

    Warning: Empty delimiter in c:\foxserv\www\gb\test.php on line 8
    And the new Data is....


  8. #8
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    sorry, I mixed up one of the two explodes - should read
    list($key, $value) = explode("=", $pair, 2);

    echoing $DATA[name] produces the correct result

    Musicman

  9. #9
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    Hey thanks music man... got the code working..however, i did have to fclose and re-open the file again inorder to update... i tried fopen("$file", 'w','r');, but that didnt work..

    here's the final:

    <?

    $file = fopen("file.txt", "r+");
    $data = fread($file, 1000);

    $pairs = explode('&', $data);
    foreach($pairs as $pair)
    { list($key, $value) = explode("=", $pair, 2);
    $DATA[$key] = urldecode($value);
    }
    fclose($file);
    $DATA[count]++;
    print "$DATA[count]";

    $update = fopen("file.txt", "w");
    $newData = "count=$DATA[count]&name=$DATA[name]&HAHAH2A";
    echo "<br>$newData";
    fwrite($update, $newData);
    fclose($update);

    echo "<br>And the new Data is....$DATA[name]<br>$DATA[count]";
    ?>


    umm... is that ok?- to close and re-open the file again in one script?

  10. #10
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    the r+ mode is supposed to allow reading, seeking to the start, and rewriting without an extra fopen. The only time you would need it ... for locking the file (in a unix environment), since closing the file in between would drop the lock

    Musicman

  11. #11
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    aight.. thanks alot man.. as always.. you've been a great help!!!

    And yeah, im almost done with my guesbook-FINALLY... ima post it on Flashkit ina few minutes...
    I PUT YOU ON CREDITS! to thank ya for your help in coding..

    peace!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center