+ini_set("log_errors", true);
+ini_set("error_log", __DIR__."/server.log");
+
+function logger() {
+ if (!ini_get("date.timezone")) {
+ date_default_timezone_set(@date_default_timezone_get());
+ }
+ error_log(sprintf("%s(%s): %s",
+ basename(getenv("SCRIPT_FILENAME"), ".php"),
+ basename(current(get_included_files()), ".inc"),
+ call_user_func_array("sprintf", func_get_args())
+ ));
+}
+
+$php = getenv('TEST_PHP_EXECUTABLE');
+if ($php) {
+ define('PHP_BIN', $php);
+} else if (defined('PHP_BINARY')) {
+ define('PHP_BIN', PHP_BINARY);
+} else {
+ // PHP-5.3
+ define("PHP_BIN", PHP_BINDIR.DIRECTORY_SEPARATOR."php");
+}
+
+foreach (array("raphf", "propro", "http") as $ext) {
+ if (!extension_loaded($ext)) {
+ switch (PHP_SHLIB_SUFFIX) {
+ case "dll":
+ dl("php_$ext.dll");
+ break;
+ default:
+ dl($ext .".". PHP_SHLIB_SUFFIX);
+ }
+ }
+}
+
+function serve($cb) {
+ /* stream_socket_server() automatically sets SO_REUSEADDR,
+ * which is, well, bad if the tests are run in parallel
+ */
+ $offset = rand(0,2000);
+ foreach (range(8000+$offset, 9000+$offset) as $port) {
+ logger("serve: Trying port %d", $port);