>  기사  >  백엔드 개발  >  PHP 명령줄에 쉘 명령을 작성하는 예

PHP 명령줄에 쉘 명령을 작성하는 예

不言
不言원래의
2018-07-26 11:28:222568검색

이 기사는 PHP 명령줄에서 쉘 명령을 작성하는 예를 공유합니다. 내용이 매우 자세하므로 도움이 필요한 친구들이 참고할 수 있기를 바랍니다.

php는 Java Perl Python처럼 실행될 수 있습니다. 이것을 더 일찍 알았더라면 아마도 Java와 Python을 배우지 않았을 수도 있다는 것을 오늘 알았습니다.

그때 Java를 배운 유일한 이유는 서버에 프로그램을 올려놓고 계속 실행하세요. PHP도 사용할 수 있는 것으로 나타났습니다.

php -h
Usage: php [options] [-f] <file> [--] [args...]
 php [options] -r <code> [--] [args...]
 php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
 php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
 php [options] -S <addr>:<port> [-t docroot] [router]
 php [options] -- [args...]
 php [options] -a
 -a    Run as interactive shell
 -c <path>|<file> Look for php.ini file in this directory
 -n    No configuration (ini) files will be used
 -d foo[=bar]  Define INI entry foo with value &#39;bar&#39;
 -e    Generate extended information for debugger/profiler
 -f <file>  Parse and execute <file>.
 -h    This help
 -i    PHP information
 -l    Syntax check only (lint)
 -m    Show compiled in modules
 -r <code>  Run PHP <code> without using script tags <?..?>
 -B <begin_code> Run PHP <begin_code> before processing input lines
 -R <code>  Run PHP <code> for every input line
 -F <file>  Parse and execute <file> for every input line
 -E <end_code> Run PHP <end_code> after processing all input lines
 -H    Hide any passed arguments from external tools.
 -S <addr>:<port> Run with built-in web server.
 -t <docroot>  Specify document root <docroot> for built-in web server.
 -s    Output HTML syntax highlighted source.
 -v    Version number
 -w    Output source with stripped comments and whitespace.
 -z <file>  Load Zend extension <file>.
 args...   Arguments passed to script. Use -- args when first argument
     starts with - or script is read from stdin
 --ini   Show configuration file names
 --rf <name>  Show information about function <name>.
 --rc <name>  Show information about class <name>.
 --re <name>  Show information about extension <name>.
 --rz <name>  Show information about Zend extension <name>.
 --ri <name>  Show configuration for extension <name>.

1. php 명령줄을 사용하여 /usr/bin/php test.php

Abbreviationphp test.php

test.php

<?php
for($i=0;$i<10;$i++){
 echo $i;
 echo &#39;\n&#39;;
}
?>

2. 스크립트 시작 #!/usr/bin/php를 한 줄에 쓰면 스크립트 실행 가능 chmod a+x test.php를 만들 수 있고 명령줄을 사용하여 스크립트를 직접 실행할 수 있습니다. 예를 들어./test .php

#!/usr/bin/php
<?php
for($i=0;$i<10;$i++){
 echo $i;
 echo " java-er.com \n";
}
?>

한 시간 동안 실행하여 PHP가 중단되는지 확인하세요. 명령줄이 영원히 실행될 수 있기를 바랍니다

#!/usr/bin/php
<?php
for($i=0;$i<360;$i++){
 echo $i;
 sleep(10);
 echo " java-er.com \n";
}
?>

3.

관련 추천:

ThinkPHP3 OSS를 사용하여 코드 작성하는 방법

PHP 코드를 사용하여 봉인 절단(코드) 구현하는 방법

위 내용은 PHP 명령줄에 쉘 명령을 작성하는 예의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.