0

I need to run a PHP function every month that checks Tor Exit Nodes, I have the function, but I'm not sure how to run it every month.

Here's the function:

$list = "http://some-tor-list.com/torlist/";
$tor = file_get_contents($list);
  • 4
    What about a cronjob? http://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php – Bernhard Jul 11 '14 at 17:10
  • You need cronjobs in linux to run your script every month. In Windows you need to check Scheduled Tasks – nl-x Jul 11 '14 at 17:11
  • @Bernhard This is going to need to be as compatible as possible, would a cronjob work on every system? –  Jul 11 '14 at 17:12
  • @user3791747 Defnitily on any unix/linux system and on windows too but different. The cronjob is only the time rule when script is executed. On windows maybe a bit different http://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron – Bernhard Jul 11 '14 at 17:14

4 Answers4

3

You have two options, using a crontab (recommended) or a script that runs constantly (not really recommended).

Using crontab you can run a PHP script the first day of every month using:

0 0 1 * * php /srv/http/tor.php

You can edit your crontab using crontab -e

or you could use the sleep function like this to run every month in PHP:

do {
    $list = "http://some-tor-list.com/torlist/";
    $tor = file_get_contents($list);

    sleep(60 * 60 * 24 * 30);
} while(true);

You should read up about the syntax of crontab, it's extremely powerful.

Jordan Doyle
  • 2,976
  • 4
  • 22
  • 38
1

What you are looking for is called a "cron job". Here is a SO question that answers how to create one:

How to create cron job using PHP?

Community
  • 1
  • 1
  • Would the same thing work on Windows? I need this to be cross-platform compatible. –  Jul 11 '14 at 17:14
  • This article seems pretty comprehensive - http://www.waytocode.com/2012/setup-cron-job-on-windows-server/ – Justen Palmer Jul 11 '14 at 17:19
  • Unfortunately it does not seem like there is a good cross platform solution to cron jobs for PHP. You'll have to set each cron us specifically for the server you are using :/ – Justen Palmer Jul 11 '14 at 17:21
1

You can use Cron to complete these

if in cpanel you'll find this easily

0 0 * * * php /home/site/cron.php

Or if you have a Dedicated server you can open cron tab

Look Here For the more crontab options

0

You need to create a php script with the content:

$list = "http://some-tor-list.com/torlist/";
$tor = file_get_contents($list);

And then use a cron job to run it every month.

Community
  • 1
  • 1