Results 1 to 8 of 8

Thread: run php code after each 10 hours

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    run php code after each 10 hours

    hi
    i have a php page and i want to run it after every 10 hours automatically. How this can be achieved pls help

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: run php code after each 10 hours

    if you're using a unix based server, look up how cron jobs work, or ask your host. if you're doing it locally or just on a windows server, look up how scheduled tasks work.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: run php code after each 10 hours

    Quote Originally Posted by kows View Post
    if you're using a unix based server, look up how cron jobs work, or ask your host. if you're doing it locally or just on a windows server, look up how scheduled tasks work.
    hi i have set up this cron job and also but i have not yet received any email from my e_mail.php
    Code:
    * * * * * /usr/bin/php -q /home/user/public_html/e_mail.php
    also i add this cron
    Code:
    ls -a
    and i received emails from my second cron. why first cron is not working?

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: run php code after each 10 hours

    hi
    i can run my second page now with the cron job, with this command
    Code:
    * * * * * /usr/bin/php -q /home/user/public_html/e_mail.php
    but i want to use header() function in in my php page which is added to cron job but i dont get it working
    Code:
    <?
    header("location : http://remote.com/page.asp");
    ?>

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: run php code after each 10 hours

    you can't use a header like that because the PHP binary is running the script, not a browser.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: run php code after each 10 hours

    Quote Originally Posted by kows View Post
    you can't use a header like that because the PHP binary is running the script, not a browser.
    So please suggest me any other option
    i have tried
    Code:
    file_get_contents
    the code is in my php page which is added in cron job is

    Code:
    <?php
    $contents = file_get_contents("http://remotesite.com/remotepage.php");
    ?>
    and the page on the remote site contain this code

    Code:
    <?php
    
    $f=fopen("remotepage.php","a")
    fwrite($f,"text added<br>");
    fclose($f);
    mail("[email protected]","Subject here","the body");
    ?>
    it works fine and when i see this page
    Code:
    http://remotesite.com/remotepage.php
    on my browser i see that new text is added into this page. But i do not get the email.

    but when i use this code in remotepage.php i get the email from the server where the original cron job page is uploaded.
    Code:
    <?php
    
    $f=fopen("remotepage.php","a")
    fwrite($f,"text added<br>");
    fclose($f);
    $c = file_get_contents("http://originalsite.com/emailpage.php")
    ?>
    and emailpage.php contain this code
    Code:
    <?php
    mail("[email protected]","Subject","The Body");
    ?>
    and i get the email this way.

    do you think that this will solve the issue?
    Last edited by chunk; Jul 3rd, 2009 at 12:22 AM.

  7. #7
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: run php code after each 10 hours

    @ Chunk,

    Is there any reason why you are using two php files? Why not combine the two?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: run php code after each 10 hours

    Quote Originally Posted by Nightwalker83 View Post
    @ Chunk,

    Is there any reason why you are using two php files? Why not combine the two?
    yes
    i have change the URL to ASPX page that is hosted on another server
    Code:
    <?php
    $contents = file_get_contents("http://remotesite.com/remotepage.aspx");
    ?>
    so i tested it with the php pages on different servers

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