简体   繁体   English

php java批处理

[英]php java batch processing

I work in Linux. 我在Linux工作。 I have 3 file (about 2Gb each containing human genome sequence). 我有3个文件(大约2Gb,每个包含人类基因组序列)。 I have java codes to process those files via web interface developed in PHP. 我有java代码通过PHP开发的Web界面处理这些文件。 The processing time is about 24 hours or even more. 处理时间约为24小时甚至更长。

How can i run the Java code from PHP so that the processing does not terminate when I close the browser. 如何从PHP运行Java代码,以便在关闭浏览器时处理不会终止。

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. 我认为它需要批量处理。

As far as I understand your question you want to call your java code from the PHP? 据我了解你的问题,你想从PHP调用你的java代码? 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. 使用上面的PHP脚本。 to execute your java code. 执行你的java代码。

To get the process inforamtion see follwoing 要获得流程信息,请参阅下文

PHP getting process information PHP获取流程信息

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. 我建议如果您有权访问源代码,您实际上可以使用Java RMI并从RMI中启动所有处理。 That way you can remove PHP from the equation. 这样你可以从等式中删除PHP。

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. 然后,如果您真的需要PHP在开始之前设置一些变量或设置,您可以在使用Java RMI开始处理之前将它们写入文件。

If you need a tutorial on how to get RMI working you can refer to: 如果您需要有关如何使RMI工作的教程,请参阅:

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

Cheers! 干杯!

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. 1)创建一个db表或配置文件,用于存储标志,例如“add_process_to_queue”。

2) From your PHP panel, you could set this flag to 1 2)在PHP面板中,您可以将此标志设置为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 3)设置一个检查此标志的cron作业,如果设置为1,则作业重置为0并启动Java程序

Based on your comment, the approach used in the accepted answer for php execute a background process should do just fine. 根据你的评论, php接受的答案中使用的方法执行后台进程应该没问题。 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). 只需启动该过程,获取进程ID并将其与启动该进程的用户一起存储在DB中(或使用可用于标识启动它的用户的文件名)。 Using the isRunning method provided (that just does a ps for the process id provided) you can check if the process is still running. 使用提供的isRunning方法(只为提供的进程ID执行ps ),您可以检查进程是否仍在运行。

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. 在Unix / Linux中,如果要启动在后台运行的进程,则必须在命令末尾添加&字符。

> java blabla &

so, call shell_execute() like this: 所以,像这样调用shell_execute():

shell_execute('java blabla &')

So it will continue processing after your script ended. 所以它会在脚本结束后继续处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM