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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:21:51+00:00 2026-05-24T12:21:51+00:00

Possible Duplicate: php in background exec() function I am trying to run two exec

  • 0

Possible Duplicate:
php in background exec() function

I am trying to run two exec commands from PHP. One is a script that might run for a few minutes and there can only be once instance of it. The second exec just checks if the first process is running and either lets you run it again or redirects you. The code is something like this.

This is the main process

$command = '/home/user/active/Nem-Swd.elf 30 > /dev/null 2>&1 & echo $!';

This is the process that checks if the other one is running already.

exec("ps ax | grep $name 2>&1", $output);

I know that in the php API it says :

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

But I don’t understand what that implies.

  • 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-24T12:21:52+00:00Added an answer on May 24, 2026 at 12:21 pm

    It means that if you run the exec command without re-routing its output, your current PHP script will wait for that command to finish before terminating the script. Since you are routing the output to standard out, I believe you should be ok. If you just ran exec($commandJob) you then would run into this problem.


    Seems that this question has already been answered:
    php in background exec() function

    At a minimum (for example) you need to do this to make it run in the background:
    exec("php test.php &");


    There are other ways to start processes that might be worth looking into as well:
    http://www.php.net/manual/en/book.pcntl.php
    http://php.net/manual/en/function.popen.php

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

Sidebar

Related Questions

Possible Duplicate: Asynchronous shell exec in PHP i need to run a java program
Possible Duplicate: PHP EOF shows only one result from loop Hello Seems like I
Possible Duplicate: php date compare I have a date that I take from the
Possible Duplicate: PHP 2-way encryption: I need to store passwords that can be retrieved
Possible Duplicate: PHP: How to remove specific element from an array? How can i
Possible Duplicate: PHP: Strip a specific tag from HTML string? Hi All, I want
Possible Duplicate: Online PHP IDE In php it is possible to run code and
Possible Duplicate: Start local PHP script w/ local Python script How do you execute
Possible Duplicate: PHP make if shorter I have an if statement that looks like
Possible Duplicate: PHP pagination class are there any PHP/Class libraries that i can utilize

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.