PHP에서 proc_open을 사용하여 Java 응용 프로그램을 호출하고 처리 할 텍스트를 전달하고 출력 텍스트를 읽습니다. Java 실행 시간이 꽤 길어서 그 이유는 대부분 읽기에 시간이 걸린다는 것을 알게되었습니다. php 또는 java의 잘못인지 여부는 확실하지 않습니다.php proc_open 입력을 java에 전달하는 중
내 PHP 코드 :
$process_cmd = "java -Dfile.encoding=UTF-8 -jar test.jar";
$env = NULL;
$options = ["bypass_shell" => true];
$cwd = NULL;
$descriptorspec = [
0 => ["pipe", "r"], //stdin is a pipe that the child will read from
1 => ["pipe", "w"], //stdout is a pipe that the child will write to
2 => ["file", "java.error", "a"]
];
$process = proc_open($process_cmd, $descriptorspec, $pipes, $cwd, $env, $options);
if (is_resource($process)) {
//feeding text to java
fwrite($pipes[0], $input);
fclose($pipes[0]);
//reading output text from java
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
}
내 자바 코드 : 나는 (독립형 파일로 크기가 ~ 200킬로바이트) 3800 개 라인의 자바 html 파일로 전달하고 있습니다
public static void main(String[] args) throws Exception {
long start;
long end;
start = System.currentTimeMillis();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String in;
String input = "";
br = new BufferedReader(new InputStreamReader(System.in));
while ((in = br.readLine()) != null) {
input += in + "\n";
}
end = System.currentTimeMillis();
log("Input: " + Long.toString(end - start) + " ms");
start = System.currentTimeMillis();
org.jsoup.nodes.Document doc = Jsoup.parse(input);
end = System.currentTimeMillis();
log("Parser: " + Long.toString(end - start) + " ms");
start = System.currentTimeMillis();
System.out.print(doc);
end = System.currentTimeMillis();
log("Output: " + Long.toString(end - start) + " ms");
}
. 이 로그 파일의 실행 시간을 부러 : 왜 입력이 출력보다 100 배 더 오래 걸릴 않습니다
Input: 1169 ms
Parser: 98 ms
Output: 12 ms
내 질문이 무엇입니까? 빨리 할 수있는 방법이 있습니까?
의 권장 사항을 고려 ** 번 ** :'새의 BufferedReader (새로운 InputStreamReader (System.in))'- 고통 스러울 수 . 물론'StringBuilder' 대신'String + ='을 쓰면 속도가 느려집니다. –