Beispiel #1
0
$logfile = dirname(__FILE__) . '/php-fpm.log.tmp';
$port = 9000 + PHP_INT_SIZE;
$cfg = <<<EOT
[global]
error_log = {$logfile}
[unconfined]
listen = 127.0.0.1:{$port}
pm.status_path = /status
pm = static 
pm.max_children = 1
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, 2);
    try {
        echo run_request('127.0.0.1', $port, '/status');
        $html = run_request('127.0.0.1', $port, '/status', 'html');
        var_dump(strpos($html, 'text/html') && strpos($html, 'DOCTYPE') && strpos($html, 'PHP-FPM Status Page'));
        $json = run_request('127.0.0.1', $port, '/status', 'json');
        var_dump(strpos($json, 'application/json') && strpos($json, '"pool":"unconfined"'));
        $xml = run_request('127.0.0.1', $port, '/status', 'xml');
        var_dump(strpos($xml, 'text/xml') && strpos($xml, '<?xml'));
        echo "IPv4 ok\n";
    } catch (Exception $e) {
        echo "IPv4 error\n";
    }
    proc_terminate($fpm);
    stream_get_contents($tail);
    fclose($tail);
    proc_close($fpm);
}
if (is_resource($fpm)) {
    $i = 0;
    while ($i++ < 30 && !($fp = @fsockopen('127.0.0.1', $port1))) {
        usleep(10000);
    }
    if ($fp) {
        echo "Started\n";
        fclose($fp);
    }
    for ($i = 0; $i < 10; $i++) {
        try {
            run_request('127.0.0.1', $port1);
        } catch (Exception $e) {
            echo "Error 1\n";
        }
    }
    try {
        run_request('127.0.0.1', $port2);
    } catch (Exception $e) {
        echo "Error 2\n";
    }
    proc_terminate($fpm);
    if (!feof($tail)) {
        echo stream_get_contents($tail);
    }
    fclose($tail);
    proc_close($fpm);
}
?>
Done
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$code = <<<EOT
<?php
echo "Test Start
";
fastcgi_finish_request();
echo "Test End
";
EOT;
file_put_contents($srcfile, $code);
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, 2);
    try {
        $req = run_request('127.0.0.1', $port, $srcfile);
        echo strstr($req, "Test Start");
        echo "Request ok\n";
    } catch (Exception $e) {
        echo "Request error\n";
    }
    proc_terminate($fpm);
    echo stream_get_contents($tail);
    fclose($tail);
    proc_close($fpm);
}
?>
Done
listen.allowed_clients=127.0.0.1
user = foo
pm = ondemand
pm.max_children = 5
EOT;
    file_put_contents("{$logdir}/{$name}.conf", $poolcfg);
    $i++;
}
// Test
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, count($names) + 2);
    $i = $port;
    foreach ($names as $name) {
        try {
            run_request('127.0.0.1', $i++);
            echo "OK {$name}\n";
        } catch (Exception $e) {
            echo "Error 1\n";
        }
    }
    proc_terminate($fpm);
    if (!feof($tail)) {
        echo stream_get_contents($tail);
    }
    fclose($tail);
    proc_close($fpm);
}
?>
Done
listen = [::]:{$port}
access.log = {$accfile}
ping.path = /ping
ping.response = pong
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, 2);
    try {
        var_dump(strpos(run_request('127.0.0.1', $port), 'pong'));
        echo "IPv4 ok\n";
    } catch (Exception $e) {
        echo "IPv4 error\n";
    }
    try {
        var_dump(strpos(run_request('[::1]', $port), 'pong'));
        echo "IPv6 ok\n";
    } catch (Exception $e) {
        echo "IPv6 error\n";
    }
    proc_terminate($fpm);
    stream_get_contents($tail);
    fclose($tail);
    proc_close($fpm);
    echo file_get_contents($accfile);
}
include "include.inc";
$logfile = dirname(__FILE__) . '/php-fpm.log.tmp';
$socket = dirname(__FILE__) . '/php-fpm.sock';
$cfg = <<<EOT
[global]
error_log = {$logfile}
[unconfined]
listen = {$socket}
ping.path = /ping
ping.response = pong
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, 2);
    try {
        var_dump(strpos(run_request('unix://' . $socket, -1), 'pong'));
        echo "UDS ok\n";
    } catch (Exception $e) {
        echo "UDS error\n";
    }
    proc_terminate($fpm);
    stream_get_contents($tail);
    fclose($tail);
    proc_close($fpm);
}
Beispiel #7
0
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, 2);
    try {
        var_dump(strpos(run_request('127.0.0.1', $port), 'pong'));
        echo "IPv4 ok\n";
    } catch (Exception $e) {
        echo "IPv4 error\n";
    }
    $pid = file_get_contents($pidfile);
    if ($pid) {
        exec("kill -USR2 {$pid}");
    } else {
        die("PID not found\n");
    }
    fpm_display_log($tail, 5);
    try {
        var_dump(strpos(run_request('127.0.0.1', $port), 'pong'));
        echo "IPv4 ok\n";
    } catch (Exception $e) {
        echo "IPv4 error\n";
    }
    proc_terminate($fpm);
    stream_get_contents($tail);
    fclose($tail);
    proc_close($fpm);
}
[global]
error_log = {$logfile}
[unconfined]
listen = [::]:{$port}
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, 2);
    try {
        run_request('127.0.0.1', $port);
        echo "IPv4 ok\n";
    } catch (Exception $e) {
        echo "IPv4 error\n";
    }
    try {
        run_request('[::1]', $port);
        echo "IPv6 ok\n";
    } catch (Exception $e) {
        echo "IPv6 error\n";
    }
    proc_terminate($fpm);
    stream_get_contents($tail);
    fclose($tail);
    proc_close($fpm);
}
ping.path = /ping
ping.response = pong-static
pm = static
pm.max_children = 2
EOT;
$fpm = run_fpm($cfg, $tail);
if (is_resource($fpm)) {
    fpm_display_log($tail, 2);
    try {
        var_dump(strpos(run_request('127.0.0.1', $port1), 'pong-dynamic'));
        echo "Dynamic ok\n";
    } catch (Exception $e) {
        echo "Dynamic error\n";
    }
    try {
        var_dump(strpos(run_request('127.0.0.1', $port2), 'pong-on-demand'));
        echo "OnDemand ok\n";
    } catch (Exception $e) {
        echo "OnDemand error\n";
    }
    try {
        var_dump(strpos(run_request('127.0.0.1', $port3), 'pong-static'));
        echo "Static ok\n";
    } catch (Exception $e) {
        echo "Static error\n";
    }
    proc_terminate($fpm);
    stream_get_contents($tail);
    fclose($tail);
    proc_close($fpm);
}