Инструменты пользователя

Инструменты сайта


Боковая панель

Связь

php_cli_v_komandnoj_stroke_command_line

PHP CLI в командной строке(command line)

  • Пример. Real-time поиск ошибок Postfix
    mail_errors.php
    <?php
    // tail -f /var/log/mail.log | php /etc/postfix/myscripts/mail_errors.php
     
    while (false !== ($line = fgets(STDIN))) {
        if
        (preg_match("/reject|warning|error|fatal|panic|Permerror/i", $line)) {
            echo $line;
        }
    }
  • Пример.
    php -r 'print_r(get_defined_constants());'
  • Пример. PHP stdin Command Line Input From User
    <?php
     
    // show them a message to enter their name
    echo "Tell us your name: " . PHP_EOL;
     
    // the script will wait here until the user has entered something and hit ENTER
    $name = read_stdin();
     
    // This will display the thank you message including their name they entered.
    echo "Thank you $name. Welcome to my site" . PHP_EOL;
     
    // our function to read from the command line
    function read_stdin()
    {
            $fr=fopen("php://stdin","r");   // open our file pointer to read from stdin
            $input = fgets($fr,128);        // read a maximum of 128 characters
            $input = rtrim($input);         // trim any trailing spaces.
            fclose ($fr);                   // close the file handle
            return $input;                  // return the text entered
    }
    ?>



php_cli_v_komandnoj_stroke_command_line.txt · Последние изменения: 2016/04/23 15:11 (внешнее изменение)