-function serve(callable $cb) {
- foreach (range(8000, 9000) as $port) {
- if (($server = stream_socket_server("tcp://localhost:$port"))) {
+ini_set("log_errors", true);
+ini_set("error_log", __DIR__."/server.log");
+
+function logger() {
+ 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");
+}
+
+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);
+ if (($server = @stream_socket_server("tcp://localhost:$port"))) {