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

The Archive Base Latest Questions

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

I’ve done a little bit of PHP coding and am familiar with aspects of

  • 0

I’ve done a little bit of PHP coding and am familiar with aspects of it.

I have made a PHP script that runs as a cron job that will pull data from a database and if certain conditions are met, some information is written to a file.

Because there may be more than one result in the database, a loop is done to run through each result in the database.

Within that loop, I have another loop which will write data to a file. A cron job is then used to call this file every minute and run the contents in the bash script.

So, the PHP loop it setup to see if the file has anything written to it by using the filesize() function. If the filesize is not zero, then it will sleep for 10 seconds and try to read it again. Here is the code:

while(filesize('/home/cron-script.sh') != 0)
{
    sleep(10);
}

Unfortunately, when the filesize is ran, it seems to place some kind of lock or something on the file. The cron job can execute the bash script without a problem and the very last command in the script is to zero out the file:

cat /dev/null > /home/cron-script.sh

But, it seems that once the while loop above is started, it locks in the original file size. As an example, I just simply put in the word “exit” in the cron-script.sh file and then ran through a test script:

while(filesize("/home/cron-script.sh") != 0)
{
    echo "filesize: " . filesize("/home/cron-script.sh");
    sleep(10);
}

The loop is infinite and will continue to show “filesize: 4” when I put in the word “exit”. I will then issue the command at the terminal:

cat /dev/null > /home/cron-script.sh 

Which will then clear the file while I have the test script above running. But, it continues to say the filesize is 4 and never returns to 0 – therefore making the PHP script run until the execution time limit is reached.

Could anyone give me some advice on how I can resolve this issue? In essence, I just need some way to reading the filesize – and if there is any kind of data in the file, it will need to loop through a sleep routine until the file is cleared. The file should clear within one minute (since the cron job calls that cron-script.sh file every minute).

Thank you!

  • 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-25T23:57:34+00:00Added an answer on May 25, 2026 at 11:57 pm

    From http://www.php.net/manual/en/function.filesize.php

    Note: The results of this function are cached. See clearstatcache() for more details.

    To resolve this, remember to call clearstatcache() before calling filesize():

    while(filesize("/home/cron-script.sh") != 0)
    {
        echo "filesize: " . filesize("/home/cron-script.sh");
        sleep(10);
        clearstatcache();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.