SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot sowhat's Avatar
    Join Date
    Jun 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Garbage collector?

    I have this weird problem that I guess belongs to this forum.

    A site receives 4 million hits per day and a PHP script logs all hits information (mysql db). At some time of the day, this logging activity is stopped and 4 minutes later these logs are processed by a cron.

    The problem is that if I do not restart mysql manually before processing the 1GB db table entries, the processing script won't work.

    Why do I have to restart it? Does this mean that there is something wrong with the PHP garbage collector? Or is there some setting for PHP or MySQL?

    Any ideas are appreciated.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll have to define "doesn't work" more clearly. Does mysql refuse you connection to the database? Does it hang indefinately? Do you get some other mysql error?

    How do you turn logging off?

  3. #3
    SitePoint Zealot sowhat's Avatar
    Join Date
    Jun 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, a cron calls the script. So, I don't know what happened exactly. But the results that should occur (if the script works) do not occur.

    The weird thing is that everything works fine when I type the URL of the script manually (after restarting mysql).

    Tonight I added a line to restart mysql (to the script) and the same disappointing result Then I simply typed the URL and it worked fine.

    Load is 0.5 maximum at the time of execution.

  4. #4
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Atlanta, GA
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure that cron is actually executing the script? You can add a line like:

    PHP Code:
    file_put_contents(dirname(__FILE__).'/test.txt''The script ran'); 
    at the beginning to make sure (check for test.txt in the same directory as the script). Other than that, if cron is executing it as a command-line script maybe there's something in the script that makes it fail unless it's executing through the web. If that's the case, I guess you could use wget in the cron job? (I'm not a *nix expert.)

    You could also try putting this at the top of the script:

    PHP Code:
    ini_set('log_errors''1');
    ini_set('error_log'dirname(__FILE__).'/errors.txt');
    error_reporting(E_ALL); 
    That should write any errors that occur as the script runs to a file called errors.txt in the same directory.

  5. #5
    SitePoint Zealot sowhat's Avatar
    Join Date
    Jun 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I will try the error logging tonight and will google if wget is better or not.

    BTW I know that the script starts because it already emails me at the beginning (as part of the script).

  6. #6
    SitePoint Zealot sowhat's Avatar
    Join Date
    Jun 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The error results from lynx and wget themselves! I applied the comments above but no luck. When I manually started it, a weird error appeared saying that network connection aborted. Then it worked from the second trial.

  7. #7
    SitePoint Zealot sowhat's Avatar
    Join Date
    Jun 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK now it is solved
    I googled until I found this page:
    http://moodle.org/mod/forum/discuss.php?d=28277
    And I started to use php command line instead. Result is 100% success.


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
  •