Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Is it possible for a PHP script to be self-executable on the server side?
    For example I have a counter script that counts hits for the month, then on the first of month (or as soon after as I can get io it) I reset the counter. I want to modify it so that it will know when to reset for the next month and store the total of the previous month into a running total .dat file.

    Any ideas?
    - Brian

  2.  

  3. #2
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    Assuming you are on Linux hosting, "crontab" is your friend here.

    Do a google search on crontab and you'll find all the required information.

    Sean

  4. #3
    Member Seraph's Avatar
    Join Date
    Sep 2003
    Posts
    81
    Member #
    3090
    well it does not have to reset every month. It only has to reset every time a vistitor sees the site. sorta hard to grasp...
    You want to reset your counter once a month? well this is what you do. in your counter storage file or mysql table you add some way to add the month. so like 45|11 45 is the number of hits and the 11 is the month use explode to get the 2 vars. So in your counter script you add
    if($month<date('m')) //reset counter here

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Probably a SQL table would be your best bet for what you're asking, although what you're asking (auto-executing code) is like a daemon... which I've never heard of in PHP, although I'm sure they must exist? Maybe that's what the crontab thing is?

  6. #5
    Senior Member tibberous's Avatar
    Join Date
    Aug 2003
    Posts
    195
    Member #
    2535
    I have recently had this problem. If you have php setup to run as cgi you might be able to use the cron daemon with it but I have never had any luck with that.

    What will work is to pop open the cgi bin and just whatever you are trying to do in Perl, that is what I ended up doing. If you don't know Perl, bug a friend to write you a script or just learn a little (if you know PHP you can pick up enough Perl to do most things in a day).

    If you are new to cgi programming, there are couple things that might cause problems. First (and I am sure this depends on your server config) if you are writing your files in notepad, you might need to change the end of line character from windows (cr lf) to unix (lf). Lots of stuff will do this, like Dreamweaver. Also, make sure to chmod 755 and to add the line #!/<path to perl> at the head of your file. Cron Jobs arn't bad, most hosting has a control panel to simplify them.

    Good luck!

  7. #6
    Senior Member Fallout's Avatar
    Join Date
    Aug 2003
    Location
    Richmond, Virginia
    Posts
    543
    Member #
    2748
    If this clears on the first of the month, you can store the day of the month into a variable and then if that var equals 1, rewrite the entire file:

    PHP Code:
    $var date("j");
    $file "text.txt";
    $code "code that will overwrite the file";
    if (
    $var == 1) {
       
    $fp fopen ($file'w'); 
       
    $fwrite ($fp$code); 
       
    $fclose ($fp);

    Is this what you mean?

  8. #7
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    If you really want to clear the stuff down, then I believe that using a cron job is the best idea.

    Create a php script, then create a shell script that contains the following...

    #!/bin/bash
    php scriptname

    Then chmod 755 the shell script, and use cron to schedule it for Midnight on 1st of each month.

    Sean

  9. #8
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    Do you have shell access, btw?

    Sean

  10. #9
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Ummmmm you don't need the php installed as CGI to run a script on cron. If the script is accessible via web, then you can use either of the following commands:

    /usr/bin/GET http://www.domain.com/script.php >/dev/null

    lynx -dump http://www.domain.com/script.php >/dev/null
    There and Back Again :Ogre:

  11. #10
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Originally posted by Fallout
    If this clears on the first of the month, you can store the day of the month into a variable and then if that var equals 1, rewrite the entire file:
    Your code is closest to what I have in mind. The only thing is with that example everytime someone visits on the first of the month the counter would reset...
    - Brian


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:59 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com