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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:19:35+00:00 2026-05-17T22:19:35+00:00

Sometimes when i run this code I get a process and id and sometimes

  • 0

Sometimes when i run this code I get a process and id and sometimes the command will execute but the data return stays empty? Does anybody know how to catch the stream properly?

/**
 * Run command in background and returns the process id
 * 
 * @param string $cmd
 * @return int process id
 */
public function runBackground($cmd)
{
    $cmd = $cmd." > /dev/null & echo $!";

    if (!($stream = ssh2_exec($this->_connection, $cmd ))) {
        return "fail: unable to execute command\n";
    } else {
        // collect returning data from command
        stream_set_blocking($stream, true);
        $data = "";

        while ($buf = fread($stream,4096)) {
            $data .= $buf;
        }

        fclose($stream);
        return (int)$data;
    }       
}
  • 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-17T22:19:36+00:00Added an answer on May 17, 2026 at 10:19 pm

    I had similar problems with my last use of the ssh2 PECL extension. It seems to be related to libssh2 somehow: I had no problems with it before, then I upgraded libssh2 and started receiving empty responses sporadicly for no apparent reason. ssh2_exec would still execute the command, but sometimes I would get output, sometimes I wouldn’t.

    Unfortunately, this extension is unmaintained since 2008 and is still in Beta state (0.11.0). You may want to look at some SSH2 3rd party libraries (some of them are LGPL or GPL). I’ve never been able to fix that issue.

    EDIT:

    2 days ago (on November 3rd, 2010), the maintainer released a patch that apparently works with the latest libssh2, although I haven’t tested it myself. You may want to upgrade to 0.11.2.

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

Sidebar

Related Questions

Has anyone ever run into this issue before? Sometimes the string displays, sometimes half
I am trying to run a program and SOMETIMES I'm getting this error when
Sometimes I run a command in cmd such as: fc /b file1 file2 and
I sometimes need to run gacutil.exe or installutil.exe, etc. from the command line. Is
Im using outproc session that is managed by aspnet_state. Sometimes I get run time
Stored procs in SQL Server sometimes finish with a return code, as opposed to
I have this simple code : ( which i run in linqpad ) void
You know how Temple Run sometimes has alerts when you open the App that
Our system uses a lot of large Bitmaps (System.Drawing.Bitmap) and sometimes we run out
I have a user of my application that sometimes when they run the application

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.