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 6540343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:58:00+00:00 2026-05-25T10:58:00+00:00

I have cron jobs setup that runs a few PHP scripts often. The issue

  • 0

I have cron jobs setup that runs a few PHP scripts often. The issue is that each time it runs a script, it create an alias of it, or an empty file with the same filename and a number added at the end.

For instance, one of the files are activesessions_update.cron.php, here is the script inside it:

<?php
  $memcache = new Memcache; 
  $memcache->connect('127.0.0.1', 11211);
  $activeSessions = $memcache->getStats(); 

  // using heredoc
$file_content = <<<TEXT
<?php

\$activeSessions = {$activeSessions['curr_items']};

?>
TEXT;

// this would be a user-defined function
file_put_contents("activesessions.php", $file_content);
?>

In my route folder, this is how it looks like: https://i.stack.imgur.com/j3kp8.png

In cPanel, the cron job runs the command:

/usr/bin/wget http://domain.com/x/activesessions_update.cron.php

I have no idea what the problem is. I am forced to delete 10,000s of these empty files every week. Please note that I have no experience in PHP programming as I did not code it myself so any replies would be appreciated with utter detail. Who can guide me to solve this puzzle?

EDIT: Got the solution from techincal support of my host:

It wasn’t logging exactly, by default wget is used to download files.
So when you run wget against that url it goes out, requests the file,
and downloads the output of the request, essentially saving a copy of
what you would get in your browser if you pulled it up. By adding the
-O /dev/null to the command you are telling it that instead of saving
that output to the default location (generally wherever it was being
called from) to save it to /dev/null which is really just nowhere
(basically just throws it away)

  • 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-25T10:58:01+00:00Added an answer on May 25, 2026 at 10:58 am

    Since we have established that these are log files created by cron, a work-around is to have the PHP script delete the log files as it is run. Change activesessions_update.cron.php to this – back up the original version in a different directory first!

    I am assuming that the files are created in such a way that the user you script is run as has permissions to delete the files. If it is not, this wont work.

    <?php
    
      $memcache = new Memcache; 
      $memcache->connect('127.0.0.1', 11211);
      $activeSessions = $memcache->getStats(); 
    
      // Removed slightly pointless heredoc
      $file_content = "<?php\n\n\  $activeSessions = {$activeSessions['curr_items']};\n\n?>";
    
      // this would be a user-defined function
      // What does the above comment mean? Are you supposed
      // to replace this with some of your own code?
      file_put_contents("activesessions.php", $file_content);
    
    
      // ========================================================
      //     Everything below here is to delete old log files
    
    
      // Change this to the directory where the log files end up
      $logsdir = "/home/USER/";
    
      // Get the name of this file and length of the name
      $filename = basename($_SERVER['PHP_SELF']);
      $namelength = strlen($filename);
    
      // Strip any trailing slashes from $logsdir
      $logsdir = rtrim($logsdir,'/\\');
    
      // Open the logs directory
      if (!$dp = opendir($logsdir)) {
        trigger_error("Could not open logs directory '$logsdir' for reading, exiting...");
        exit;
      }
    
      // Loop through the files in the directory
      while ($file = readdir($dp)) {
        if (!in_array($file,array('.','..',$filename)) && strlen($file) > $namelength && substr($file,0,$namelength) == $filename) {
          // If the start of the file name is the same as this file,
          // and the file name length is longer than the length of the
          // name of this file, delete it.
          @unlink("$logsdir/$file");
        }
      }
    
      // Close the directory pointer
      @closedir($dp);
    
    ?>
    

    I guess the cron daemon on your server is configured to redirect STDOUT and STDERR of all the cron jobs it runs to a file. It seems odd that it is configured like this, as it will cause problems like you are having. Also, it seems very odd that it should redirect them to files that have, essentially, the same name of your script with a number on the end. You would have though they would be *.log or something.

    This solution will still leave at least one log file in existence at any one time, because you definitely wont be able to delete the file that is currently being written to.

    If this does work, you can safely copy/paste the same code (from below the ===== comment line) into any other files that are called by cron jobs and are causing the same problem, as long as they are:

    • creating the log files in the same directory that the script resides
    • the only file in the directory (that you actually want) where the file name starts with the full name of the script file
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cron entry that runs a script at a certain time each
I want to setup a CRON that runs a PHP script that in turn
I have a CRON job php script that I just set up not too
I have this bash script on the server that runs every hour, via cron.
I have cron job - php script which is called one time in 5
I have two ruby script cron jobs that I'm trying to run under Ubuntu
I have several cron jobs (calling my PHP scripts via curl ) in the
I have few bash scripts which are adding to cron jobs with specified timing,
We have several cron jobs that ftp proxy logs to a centralized server. These
I have 5-6 jobs to be done by cron, and i have separated php

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.