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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:13:53+00:00 2026-05-13T21:13:53+00:00

Objective: My script will download a remote file upon form submission, since the file

  • 0

Objective:
My script will download a remote file upon form submission, since the file might be big, I would like to fork off a process and let the user go on with his/her life.

Example of a command:

wget -q –limit-rate=1k –tries=10 “http://helios.gsfc.nasa.gov/image_euv_press.jpg” -O /web/assets/content/image/image_euv_press.jpg

Method tried:

  1. pcntl forking,

        $pid = pcntl_fork();
    
        if ( $pid == -1 ) {
            exit;
        } else if ( $pid ) {
            //We are the parent process, the pid is child pid right?
    
            return $pid;
        } else {
            // We are the child process
    
            exec($command.' > /dev/null');
            // > /dev/null &
    
            posix_kill(getmypid(),9);
            return;
        }
    

I do get the PID but then there is a risk that the forked process becomes a zombie and since I am using nginx -> php-fpm (tested and confirmed, upon running several times alot of defunct php-fpm processes), I would have to restart the server just to eliminate the zombies, this would leave me to PID exhaustion attack? ( I am guessing)

  1. Background process:

            exec($command . ' > /dev/null &');//background process
        $proc = passthru ("ps aux | grep '$command'");//search for the command
        echo var_dump($proc);
        $pid = (int)(next(explode(' ',$proc)));//parse the pid (not implemented)
    

Question:
the background process method works but it’s not clean, is there a better way to fork off a process to download and get that wget command PID so I can kill it later?.

I have tried echoing $! after doing the exec just to get the PID but exec(‘echo $!’) doesnt return anything, i think it’s because every exec is a different “space”

I added ‘> /dev/null 2>/dev/null &’ to the end of the command on my terminal it would return something like: [3] 30751, but through php exec, there is no way to capture that returned PID.

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-13T21:13:54+00:00Added an answer on May 13, 2026 at 9:13 pm

    Try the following command:

    exec("ps -C $command -o pid=", $pids);

    But I recommend you to use Zend Server Job Queue, which exists for these objectives.

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

Sidebar

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.