CRON - Excute a php script

  • I have a small PHP script which opens the captive portal DB, and then kicks all users from it.  This works fine if I place it in the www folder and execute from a web page.

    I thought I could put the php script into the /usr/local/pkg directory, and then use the CRON package to setup a time each day to execute this (just past midnight).

    I have tried to set the cron job up to execute every 2 minutes to test, and it never fires, and I see no system logs?

    Will a PHP script execute from a cron job?


  • Ah, Ok.

    I think I had the command wrong.  It works if i use this:  /usr/local/bin/php /usr/local/pkg/kickallusers.php 0

    I was originally just calling /usr/local/pkg/kickallusers.php (similar to what squid does in one it's cron jobs).

    This now works fine.

    For interest, kickallusers.php contains this:

    All the echoed HTML could be lost, as there is no need.  I wanted to do this to force all clients to disconnect at the same time, and not after xx amount of hours.

    echo "Opening Captive Portal Database....................";
    if (file_exists("/var/db/captiveportal.db")) {
      $captiveportallck = lock('captiveportaldb');
      $cpcontents = file("/var/db/captiveportal.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    echo "DONE.";
    echo "
    $cnt = 0;
    foreach ($cpcontents as $cpcontent) {
      $cpent = explode(",", $cpcontent);
      $oursid = $cpent[5];
      echo "";
      echo "";
    $fh = fopen("/usr/local/pkg/kickallusers.log", 'w');
    if(flock($fh, LOCK_EX)){
      fwrite ($fh, date('l jS \of F Y h:i:s A'));
      flock($fh, LOCK_UN);
    if($cnt != 0){
      echo "
    | Disconnecting [ MAC: $cpent[3] ]   |   [ IP: $cpent[2] ]   |   [ ID: $cpent[5] ]..................... | DONE.
    Completed successfully, $cnt clients disconnected.";
      echo "
    There where no clients to disconnect!";
    I know the echo's will all buffer out together in this script, they were more just to see the finished output, not a 'rolling report'.
    My Captive Portal page has some PHP in it which does a time check, preventing the client from passing through the captive portal between midnight and 7am, the captive portal page that appears says the "Internet Access is currently turned off'.  Outside these times, the normal captive portal page appears.
    The reason for this kicking script is to kick all clients just after midnight, forcing them to re-visit the captive portal page, which would then show the "Internet Access is currently turned off" page.

Log in to reply