やりかたもそんなに難しくなかった、なんで解説してるサイトが存在しないんだろう・・・
とりあえず早速やり方
QuercusのサイトにいってQuercusの最新版warファイルを入手する。
WEB-INF/libの中のinject-16.jar、javamail-141.jar、resin.jarと
javax.servletのライブラリ(僕はjavaee-api-5.1.1.jarを使いました。)
を準備する。
あとは以下のプログラムで動作します。
Java側
package com.ttProject.quercus;
import java.io.IOException;
import com.caucho.quercus.Quercus;
public class Main extends Quercus{
/**
* @param args
*/
public static void main(String[] args) {
Main q = new Main();
q.parseArgs(args);
q.setFileName("path to PHP program");
q.init();
q.start();
try {
for(int i = 0;i < 8;i ++) {
long start = System.currentTimeMillis();
q.execute();
long end = System.currentTimeMillis();
System.out.println("Time spent = " + (end - start) + "ms");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Main() {
super();
init();
}
}
PHP側<?php
echo "start";
$val = 0;
for($i=0;$i < 100000;$i ++){
$val += $i;
}
var_dump($val);
echo "end"
動作結果はこんな感じ
startint(4999950000)
endTime spent = 122ms
startint(4999950000)
endTime spent = 39ms
startint(4999950000)
endTime spent = 17ms
startint(4999950000)
endTime spent = 16ms
startint(4999950000)
endTime spent = 16ms
startint(4999950000)
endTime spent = 18ms
startint(4999950000)
endTime spent = 16ms
startint(4999950000)
endTime spent = 16ms
JITコンパイルも効いてるみたいですね。よきかなよきかな