<commit_before><?php

/**
 * Created by PhpStorm.
 * User: renwuxun
 * Date: 2016/8/8 0008
 * Time: 10:29
 */
class PHPServer_Helper {

    public static function ifServerRunning($pidFile) {
        return file_exists($pidFile) && posix_kill((int)file_get_contents($pidFile), 0);
    }

    public static function writePidFile($pidFile) {
        $path = substr($pidFile, 0, strrpos($pidFile, '/'));
        if (!is_dir($path)) {
            mkdir($path, 0775, true);
        }
        if (file_put_contents($pidFile, posix_getpid())) {
            register_shutdown_function(function() use($pidFile) {
                if (file_exists($pidFile) && posix_getpid() == (int)file_get_contents($pidFile)) {
                    unlink($pidFile);
                }
            });
            return true;
        }
        return false;
    }

    public static function checkContinue($cmd, $pidFile) {
        global $argv;
        switch ($cmd) {
            case 'start':
            case 'daemon':
                if (self::ifServerRunning($pidFile)) {
                    fprintf(STDERR, PHPServer_Log::format("{$argv[0]} is running\n", PHPServer_Log::LEVEL_WARNING));
                    exit(1);
                }
                break;
            case 'stop';
                if (!self::ifServerRunning($pidFile)) {
                    fprintf(STDERR, PHPServer_Log::format("{$argv[0]} is not running\n", PHPServer_Log::LEVEL_WARNING));
                    exit(1);
                }
                posix_kill((int)file_get_contents($pidFile), SIGTERM);
                exit(0);
                break;
            case 'reload';
                if (!self::ifServerRunning($pidFile)) {
                    fprintf(STDERR, PHPServer_Log::format("{$argv[0]} is not running\n", PHPServer_Log::LEVEL_WARNING));
                    exit(1);
                }
                posix_kill((int)file_get_contents($pidFile), SIGHUP);
                exit(0);
                break;
            default:
                echo "usage:\n";
                echo "      php {$argv[0]}\n";
                echo "      php {$argv[0]} daemon\n";
                echo "      php {$argv[0]} stop\n";
                echo "      php {$argv[0]} reload\n";
                die();
        }
    }
<commit_msg>优化PHPServer_Helper<commit_after><?php

/**
 * Created by PhpStorm.
 * User: renwuxun
 * Date: 2016/8/8 0008
 * Time: 10:29
 */
class PHPServer_Helper {

    public static function ifServerRunning($pidFile) {
        return file_exists($pidFile) && posix_kill((int)file_get_contents($pidFile), 0);
    }

    public static function writePidFile($pidFile) {
        $path = substr($pidFile, 0, strrpos($pidFile, '/'));
        if (!is_dir($path)) {
            mkdir($path, 0775, true);
        }
        if (file_put_contents($pidFile, posix_getpid())) {
            register_shutdown_function(function() use($pidFile) {
                if (file_exists($pidFile) && posix_getpid() == (int)file_get_contents($pidFile)) {
                    unlink($pidFile);
                }
            });
            return true;
        }
        return false;
    }

    public static function checkContinue($cmd, $pidFile) {
        global $argv;
        switch ($cmd) {
            case 'start':
            case 'daemon':
                if (self::ifServerRunning($pidFile)) {
                    fprintf(STDERR, "{$argv[0]} is running\n");
                    exit(1);
                }
                break;
            case 'stop';
                if (!self::ifServerRunning($pidFile)) {
                    fprintf(STDERR, "{$argv[0]} is not running\n");
                    exit(1);
                }
                posix_kill((int)file_get_contents($pidFile), SIGTERM);
                exit(0);
                break;
            case 'reload';
                if (!self::ifServerRunning($pidFile)) {
                    fprintf(STDERR, "{$argv[0]} is not running\n");
                    exit(1);
                }
                posix_kill((int)file_get_contents($pidFile), SIGHUP);
                exit(0);
                break;
            default:
                echo "usage:\n";
                echo "      php {$argv[0]}\n";
                echo "      php {$argv[0]} daemon\n";
                echo "      php {$argv[0]} stop\n";
                echo "      php {$argv[0]} reload\n";
                exit(0);
        }
    }

{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.014699231117141566, 'mean_word_length': 1.4932356257046224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '323686', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1246, 'n_words': 235}