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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:54:55+00:00 2026-06-17T21:54:55+00:00

I want to write a php script to run on background. that needs pcntl_fork.

  • 0

I want to write a php script to run on background. that needs pcntl_fork.
I use this function to fork a child :

function launchchild($programexe,$programvars) 
{ 
//foreach ($tasks as $key => $v){ 
switch ($pid = pcntl_fork()) { 
  case -1: 
     // @fail 
     die('Fork failed'); 
     break; 

  case 0: 
     // @child: Include() misbehaving code here 
     pcntl_exec($programexe,$programvars);
     break; 

  default: 
     // @parent 
     //pcntl_waitpid($pid, $status); 
     break; 
} 

//print "Done! :^)\\n\\n"; 
}

i call it with a snippet like below so much in a minute:

$parameters = array('/Applications/XAMPP/xamppfiles/htdocs/ping/senario2/master/gather_checks.php', $serialize_triagger, $server_list[$server_choose]);
launchchild('/Applications/XAMPP/xamppfiles/bin/php',$parameters); // fork a child for parallel processing.

so, it works gracefully only for some minute.
i checked the process with ‘ps -ax | grep php’. i saw there is so much process that never end until the code will give 35 error that means we have not more memory to run that!
this is the result of ‘ps -ax | grep php’

ps -ax | grep php
12020 ttys001    0:00.07 /Applications/XAMPP/xamppfiles/bin/php /Applications/XAMPP/xamppfiles/htdocs/ping/senario2/master/main.php
12021 ttys001    0:00.00 (php-5.3.1)
12022 ttys001    0:00.00 (php-5.3.1)
12025 ttys001    0:00.00 (php-5.3.1)
12028 ttys001    0:00.00 (php-5.3.1)
12037 ttys001    0:00.00 (php-5.3.1)
12040 ttys001    0:00.00 (php-5.3.1)
12043 ttys001    0:00.00 (php-5.3.1)

when i uncomment the //pcntl_waitpid($pid, $status); it work like a charm without any problem, ever. but i don’t want the parent wait for child work.
any thing can be helpful.

  • 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-17T21:54:56+00:00Added an answer on June 17, 2026 at 9:54 pm

    You’re launching another program/script, so you don’t need any forking, just use system() and screen for taking terminal (idk if & works)

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

Sidebar

Related Questions

I want to write a PHP script that will run as a cron job
I want to write a php script that keeps the apache_log file open and
Say I want a php script the run the function itstime() every hour. Other
I want to write a php script to compare rows from the database and
I want to write a program to contact a PHP script online, and show
I want to write a php code that can search for multiple keywords separated
Simple question I guess, I want to use PHP to write an update to
I am trying to write an php twitter script which will be run by
I want to run php or python scripts from eclipse that will create folders
I want to run a php script ( for example mail.php ) when anyone

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.