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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:32:45+00:00 2026-05-27T04:32:45+00:00

Apologies if this has been covered before – I did my searching but possibly

  • 0

Apologies if this has been covered before – I did my searching but possibly may not know the correct terms to have used.

This process is handled with PHP.

Here’s the situation:

I have a large array of file names. The script I have opens these files and enters their content into a database. Processing these files one at a time takes over 24 hours, and these files are updated on a daily basis.

Breaking the single large array into four smaller arrays and running concurrent processes finishes the job before the 24 hour window elapses, but sometimes one or two processes will finish hours before the others because file sizes vary on a daily basis.

Much like people who stock retail shelves (who else has worked that nightmare before?) pitch in to help out with what’s left after finishing their own tasks, I’d like to have a script in place where these “agents” do the same.

Here’s some basics of what I have figured out – it could be wrong, and I’m not too proud to protest if I am 🙂

$files = array('file1','file2','file3','file4','file5'); 
//etc... on to over 4k elements

while($file = array_pop($files)){

    //Something in here...  I have no idea what.

}

Ideas? Something like four function calls or four loops within that overarching ‘while’ has crossed my mind, but I’m pretty sure it’s going to wait on executing subsequent calls until the previous one(s) finish.

Any help is appreciated. I’m seriously stuck on this one!

Thanks!

  • 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-27T04:32:45+00:00Added an answer on May 27, 2026 at 4:32 am

    A database-backed message queue seems the obvious solution but I think that’s overkill in this case. I would simply put the files to be processed into a single dedicated queue directory, then use the DirectoryIterator class to scan it. Something like this:

    while (true) {
        look in the queue directory for a file
        if you don't fine one, exit the script, all processing is done
        if you find one, rename it or move it to a work directory
        if the rename/move command succeeded, process the file
        if the rename/move command failed, one of the other threads got it first
    }
    

    Edit:

    Regarding launching the workers, you could use a simple shell script to spawn the PHP processes in the background:

    NUM_WORKERS=5
    for WORKER in $(seq 1 ${NUM_WORKERS})
    do
        echo "starting worker ${WORKER}"
        php -f /path/to/my/process.php &
    done
    

    Then, create a cron entry to run this launcher, for example, at midnight:

    0 0 * * * /path/to/launcher.sh
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My apologies if this has been answered before or is obvious...did some searching here
I apologize because I know this has been covered over and over again, but
Apologies if this has been asked before (I couldn't find the answer anywhere), but
My apologizes if this has been covered before; I searched and searched but I
Folks, Apologies if this has been covered in another thread, but I have searched
Apologies if this has been answered before, but I find it very difficult to
Apologies if this has been asked before but it seems an obvious question for
Apologies if this has been asked before but is there any way, at all,
apologies if this has been answered before, I couldn't dig anything up when searching.
Apologies if this has been answered before but I can't find a reference. I

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.