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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:17:12+00:00 2026-06-04T00:17:12+00:00

I am running php scripts in parallel on an AWS lamp server. Right now

  • 0

I am running php scripts in parallel on an AWS lamp server. Right now I have a cron job set up to run each script at 10 min intervals, and then the script is set to exit after running for 20mins. I limit the time each script runs to keep from running out of memory on the server. I have tried to plug the memory holes as best I can, but as I work on this, timing out the script is a good interim solution.

The problem is I get too many scripts running at the same time. So rather than use cron to run the scripts at set intervals, how can I script the server to

A) monitor how many instances of specific php script are running at any given moment

B) if that number drops below n (say 4 instances) the server would fire up another instance of the php script?

Thanks for the help still learning my way around linux!

  • 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-06-04T00:17:14+00:00Added an answer on June 4, 2026 at 12:17 am

    The best way would likely be to write your own daemon which runs, forks child processes, monitors them, and will restart them as needed.

    Take a look at http://php.net/manual/en/book.pcntl.php

    However, in your case, there may be a simpler answer… Put a one minute crontab in place which calls your loader script, like this:

    * * * * *  /usr/bin/php /path/to/loader.php
    

    The loader script can be a simple shell script (or php script). Run this command in the shell. It will return the number of instances of the script you are running.

    ps aux | grep "/usr/bin/php /path/to/thing/you/run.php" | grep -v grep | wc -l
    

    If # instances > 3, then do not start one. Otherwise, start one. If in PHP, you can simply include the desired file. If in bash, just write /usr/bin/php /path/to/thing/you/run.php

    Hope it helps some!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some long-running CLI PHP scripts that run regularly via cron. I'd like
I have couple of php scripts which are called by cron. The cron job
I have installed WAMP and running PHP scripts on localhost. I have enabled cURL.
I have a dedicated server running Cent OS with a Parallel PLESK panel. I
I have php scripts that I have to run on linux as well as
I have installed my PHP scripts which runs over Apache server in a Windows
I have a CentOS 6 server set up with git, gitosis, nginx, and php-fpm.
When running php scripts on the iSeries, even though I set my memory limit
Well, I have 3 different php scripts and actually it is running by a
I have several cron jobs (calling my PHP scripts via curl ) in the

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.