Search code examples
javaphpdrupalshellubuntu-server

How can I save a process resource from proc_open in order to check the status later on?


I'm running a sh script that runs a java process through php on ubuntu server. I'm using proc_open for running the process. usually the Workflow goes like :

  • request a page ->
  • script runs (until it's finished) ->
  • result page.

In my case the script runs in parallel so the server won't wait until the script is finished (it takes hours sometimes so it can't) , so I need to save that resource somehow to follow it later (status of the process or just stopping it).

The resource type is "process", I used this function get_resource_type for getting it.

Serialize won't work at this case - resource is an exceptional for it (you can look at http://il2.php.net/manual/en/function.serialize.php inside the Parameters box).

My target is a good process handling. does someone know how can i use the resource or other way you would do for process handling.


Solution

  • You can't store resource types for later use in PHP. What you need to do is implement some form of asynchronous communication - maybe a file, where one writes status information and the other one reads, a shared memory, a named pipe, ...

    I would look into the pcntl extension. Hint: Forking is not possible from within a web-server environment for security reasons.