0

I work in Linux. I have 3 file (about 2Gb each containing human genome sequence). I have java codes to process those files via web interface developed in PHP. The processing time is about 24 hours or even more.

How can i run the Java code from PHP so that the processing does not terminate when I close the browser.

Since the processing time is so long, it is not practicable to keep the browser open until the process get completed.

I assume it requires batch processing.

World
  • 2,007
  • 7
  • 27
  • 37
  • What exactly is your problem? The fact that you don't know how to start a background process? And what do you expect to happen on the PHP front-end regarding the process once it's started (since you don't want to keep the browser open)? – wimvds May 17 '11 at 07:18
  • possible duplicate of [php execute a background process](http://stackoverflow.com/questions/45953/php-execute-a-background-process) – wimvds May 17 '11 at 07:19
  • i need to run the process in the background, but the process gets initiated from webpage (lets say after pressing submit button). Then i need to keep track of the running process of each users, which should be visible from user pages to different users. – World May 17 '11 at 07:25

5 Answers5

2

As far as I understand your question you want to call your java code from the PHP? correct? so here is the solution

<?php
    //use system call to execute java class or jar
    system('java yourclass', $retval);
?>

use the above php script. to execute your java code.

To get the process inforamtion see follwoing

PHP getting process information

Muhammad Ummar
  • 3,541
  • 6
  • 40
  • 71
  • how can i keep track of the process. i mean how can i get the process id of this event. – World May 17 '11 at 07:35
  • @Bishwo, you will not get the id of process, however you can make some log in your java file which will give you an idea of your java code. moreover see the @Savas Alp answer as well. – Muhammad Ummar May 17 '11 at 09:16
  • @Ummar it is possible to get process id from java code. I wonder if same is possible in PHP. As far as i know PHP does not provide functionality of giving process id of executed command. My work will really be easy if i can get the process id in PHP code. – World May 17 '11 at 10:06
  • @Ummar your answer helped me, but got another problem. proc_get_status() gives the process id only after complete execution of the command in proc_open(). So it restricts me to run the the process in the background. system('java yourclass', $retval); runs in the background, which is pretty nice, but i do not get process-id from this. What do you say about Zend Queue in Zend Platform. I have not used it though. – World May 17 '11 at 15:08
  • @Bishwo, `system` doesn't give you process ID, you might see in to Zend Queue as I am not very much familiar with that as well. – Muhammad Ummar May 18 '11 at 08:30
0

May I suggest that if you have access to the source code, you can actually make use of Java RMI and the launch all your processing from within RMI. That way you can remove PHP from the equation.

Then again, if you really need the PHP to set some variables or settings before you begin, you can write those to a file before you use Java RMI to begin your processing.

If you need a tutorial on how to get RMI working you can refer to:

http://download.oracle.com/javase/tutorial/rmi/index.html

Cheers!

Vern
  • 2,393
  • 1
  • 15
  • 18
0

This is my proposed solution:

1) Create a db table or a config file where to store a flag, "add_process_to_queue" for example.

2) From your PHP panel, you could set this flag to 1

3) Set up a cron job that checks for this flag and if it is set to 1, the job resets to 0 and starts the Java program

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Fabrizio D'Ammassa
  • 4,729
  • 25
  • 32
0

Based on your comment, the approach used in the accepted answer for php execute a background process should do just fine. Just start the process, fetch the process id and store it in a DB together with the user that started the process (or use a filename that can be used to identify the user that started it). Using the isRunning method provided (that just does a ps for the process id provided) you can check if the process is still running.

Community
  • 1
  • 1
wimvds
  • 12,790
  • 2
  • 41
  • 42
0

In Unix/Linux, if you want to start a process that runs on the background, you must add & character at the end of the command.

> java blabla &

so, call shell_execute() like this:

shell_execute('java blabla &')

So it will continue processing after your script ended.

Savas Alp
  • 194
  • 2