views:

135

answers:

2

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.

+1  A: 

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.

soulmerge
tnx ver much - I wrote the process id inside a file and handled it with unix command from php.
Adi
A: 

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) ..

That shouldn't be a problem on its own. You can easily have a long running php-process, as long as it's not initiated from a web server. If you need to initiate the process from a web application, I would suggest that you insert an entry in a database table, and then have a cronjob run a script, which checks this queue and do the processing.

troelskn