SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why would this be reseting?

    Ok So I have multiple crons running each miniute running the same php script.

    This is the php:

    PHP Code:
    $thefile "num.txt"/* Our filename as defined earlier */





    $num5 file_get_contents($thefile);


    $num $num5 1;


    $openedfile fopen($thefile"w");
    fwrite($openedfile$num);
    fclose($openedfile); 
    So say I start off with 6500... it will increase by 10 each time (Because I have 10 cron jobs running each minitue)... than randomly it resets to "1".

    If you have no explanation maybe there is another solution to raising a digit in a txt file by 1 each time the script runs
    How does that make your feel?

  2. #2
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    file_get_contents() may be invoked at the time of a write to the file, so it fails, and returns false. false + 1 = 1.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by earl-grey View Post
    file_get_contents() may be invoked at the time of a write to the file, so it fails, and returns false. false + 1 = 1.
    ahh that would explain it... now how would I go about solving this problem. Hmm. Maybe I could change something in the cron job?
    How does that make your feel?

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Should you be obtaining a lock first?

  5. #5
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Should you be obtaining a lock first?
    Can you do that via cron job or is that something in PHP I can do.
    How does that make your feel?

  6. #6
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you think of this :

    http://us3.php.net/flock

    PHP Code:
    <?php

    $fp 
    fopen("/tmp/lock.txt""w+");

    if (
    flock($fpLOCK_EX)) { // do an exclusive lock
        
    fwrite($fp"Write something here\n");
        
    flock($fpLOCK_UN); // release the lock
    } else {
        echo 
    "Couldn't lock the file !";
    }

    fclose($fp);

    ?>
    How does that make your feel?

  7. #7
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    >How does that make your feel?

    Dunno. Tell me if it works or not, then I'll tell you.

    Justified and Ancient?

  8. #8
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    >How does that make your feel?

    Dunno. Tell me if it works or not, then I'll tell you.

    Justified and Ancient?
    lol, that's his/her signature.

    Good luck on the exam BTW, considering one myself soon.

  9. #9
    SitePoint Addict
    Join Date
    Apr 2005
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I said screw it all together and decided to use mysql. I'm a idiot for trying to use .txt files... thanks for the help though everyone.

    btw, good luck on the exam.
    How does that make your feel?


Bookmarks

Posting Permissions

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