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

  • Home
  • SEARCH
  • 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 8628931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:40:41+00:00 2026-06-12T08:40:41+00:00

I am working on a shell script in cakephp that processes a queue of

  • 0

I am working on a shell script in cakephp that processes a queue of items in my mysql database. To speed up the process I am using pcntlfork like so:

$pids = array();
$i = 0;
for($i = 0; $i < count($queue); $i++) 
{

     $pids[$i] = pcntl_fork();

      if(!$pids[$i]) {
        # do code
        exit();
      } 
    }

While this code is executing the shell script may run before the current script has time to delete the items from the queue. I was using mysql and locking the table like so:

$this->Queue->query("SELECT GET_LOCK('".$this->mysqlLock."', ".$this->mysqlLockTime.") AS 'GetLock'");

This implementation does not work giving me the error “General error: mysql server has gone away”. This is because the connection is lost in the children. It appears to be a flaw within fork itself in php.

My question is there a better solution to locking this processes until it finishes and then releasing it for the other shell scripts to execute?

  • 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-12T08:40:44+00:00Added an answer on June 12, 2026 at 8:40 am

    I have found the best solution to assure that the program does not call and execute a instance of itself. I will be using semaphores in php to lock the program.

    Here is a short tutorial on semaphores:
    http://www.re-cycledair.com/php-dark-arts-semaphores

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

Sidebar

Related Questions

I am working on a Bash shell script that does something like this: #!/bin/bash
I'm working on a Bash shell script that runs several Python scripts like so:
I'm working on a project that essentially creates files via a shell script using
I would like a shell script that does a quick upload/download speed check of
I'm working on a shell script that does certain changes on a txt file
Im working on a Java Application that edits Pdf files. Furthermore a shell script
G'day, I'm getting syntax errors when working with a shell script like the following:
Below is my shell script that is working fine. #!/bin/bash DATE_YEST_FORMAT2=`perl -e 'use POSIX
I am using awk in shell script and it is working as expected. awk
i am using shell script to monitor the working of a php script. My

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.