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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:35:41+00:00 2026-06-06T13:35:41+00:00

I am trying to execute a process using proc_open. The I/O for the process

  • 0

I am trying to execute a process using proc_open. The I/O for the process is handled by the pipes !!

$descriptorspec = array(
    0 => array("pipe", "r"),
    1 => array("pipe", "w"),
    2 => array("pipe", "w")
);

Now, as it happens, sometimes the “c program” that I have opened does get stuck, and I have added a max_time_limit check which would forcibly shut down the process. I have added callback function — namely onExit — (using “call_user_function”) to process the information whenever the “process exits” in a valid manner or by force.

In the “exit” function, I am closing the i/o pipes

 foreach ($pipes as $pipe) {
    fclose($pipe);
 }

The above works perfectly fine if the process has had a valid exit. However, in the case when I forcibly killed my process, I called proc_terminate to do so. I understand that the termination of process would also go ahead and close any I/O pipes, but the problem is that due to callback, my “onExit” function process always gets called (and this is the way I want it to be…as I need to do some more processing). Now, in this case, as I try to close the pipes, I get the following error:

fclose(): 18 is not a valid stream resource 

I tried using “ftell” to check whether the pipe is valid or not, but that too errored out. How do I check whether the pipes have already been closed or not??

  • 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-06T13:35:43+00:00Added an answer on June 6, 2026 at 1:35 pm

    What about checking if the resource is still a resource before trying to close it:

    foreach ($pipes as $pipe) {
      // Finds whether a variable is a resource
      if(is_resource($pipe)) {
        fclose($pipe);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to execute a batch file using the Process class. This code
Am trying to execute ssis package using dtexec utility from c# app(Creating New Process,
I am trying to execute a batch file from C# code using Process class.
I'm trying to execute JavaScript functions that are called when a event (for example
Im trying to implement a scenario using threads to execute concurrent commands on a
I am using popen to execute a command under linux, then 4 process wile
I'm trying to post-process the documentation XML file as a post-build XSLT transformation (using
Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but
I am trying to execute some Linux commands from Java using redirection (>&) and
I'm trying to execute a series of commands using Pythons subprocess module, however I

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.