Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:25:05+00:00 2026-05-27T23:25:05+00:00

I had found a script that supposedly schedules a script to execute. I am

  • 0

I had found a script that supposedly schedules a script to execute. I am very new to PHP and I do NOT want to use cron. Here’s the script I found:

<?php 
$hour = date('G');
$day  = date('N'); // 1..7 for Monday to Sunday

if (($hour >= 5  && $hour <= 7)  // 5am - 7am
||  ($hour >= 10 && $hour <= 12) // 10am - 12 noon
||  ($hour >= 15 && $hour <= 19) // 3pm - 7pm
||  ($day == 5)                  // Friday
) { ?>
 //my script
<?php } ?>

Because I know so little, If I put my script where it says, would it execute at that certain time every time that happens? Thank you in advance! -Ben

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:25:06+00:00Added an answer on May 27, 2026 at 11:25 pm

    Better way is to use cron. This is quite simple, although it may look intimidating at first:

    Step 1 – Create a script that will be run by cron

    For example, place this in <your-app-root>/cron.php:

    <?php
    $CRON_KEY = "some-random-value-here";
    if ($_GET['key'] != $CRON_KEY) {
        header(“HTTP/1.0 403 Forbidden”);
        echo "You have no rights to access this page.";
        exit();
    }
    
    // Your code here
    

    Step 2 – Add crontab entry

    To automatically execute your cron.php script, you can add a line like this to /etc/crontab:

    ## This will run each day at 2:30 AM
    30 2    * * *   www-data    wget -O - -q http://yourdomain.com/cron.php?key=some-random-value-here &> /tmp/my-app-cron.log
    

    ..where some-random-value-here must match the random value placed in the PHP script. This is a security feature to prevent anybody from running your cron code.

    Crontab line description

    The first five parts of crontab line are: minutes, hours, day of month, month, day of week.

    You can also use ranges, for example to run the script each day at 5, 7, 8, 12, 13, 14, 15, 20 you can use this:

    0 5-8,12-15,20    * * *    ...
    

    You can also use “steps”, for example to run every 5 minutes (suggested for recurrent jobs, such as indexing / cleanup tasks, etc):

    */5 *    * * *    ...
    

    The sixth argument is the user that will be used to execute the command. You can use whichever user you want here, www-data, nobody, your user, etc. Best practice is to never use root here, unless really needed for some reason.

    The remaining part of the line is the command that will be run at scheduled time.

    The &> /tmp/my-app-cron.log part will make all the output from your latest cron.php execution to be stored inside /tmp/my-app-cron.log.

    Read more..

    For more information on cron usage, you can refer to crontab(5):

    $ man 5 crontab
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've consistently had an issue with parsing XML with PHP and not really found
For my new website I wanted to use a Facebook-button/icon I had found, different
I've had a new found interest in building a small, efficient web server in
I once found a web site that had some 'Requires .net 1.0', 'Requires .net
I had posted a question in regards to this code. I found that JTextArea
After I uploaded my application created using cakephp, I found out that I had
I have a facebook application that was using a CFC I had found on
recently I had to write a little script that parsed VMs in XenServer and
The day came when I had to write a BASH script that walks arbitrary
We recently had some issues where a sql script that would remove duplicate entries

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.