亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    關(guān)于php命令行模式介紹

    關(guān)于php命令行模式介紹

    php全集行模式,即php-cli,官方文檔中稱(chēng)為: CLI SAPI(Server Application Programming Interface,服務(wù)端應(yīng)用編程端口).聽(tīng)著挺復(fù)雜。其實(shí)是因?yàn)閜hp原本為服務(wù)器端的腳本語(yǔ)言,所以引申出這個(gè)叫法。

    與服務(wù)端模式的不同

    服務(wù)端模式主要有兩種工作方式: 作為web server的模式方式或作為一個(gè)cgi可執(zhí)行程序. 前者,比如作為apach中的一個(gè)模塊(如:php5apache2.dll); 后者作為可執(zhí)行程序,如php-cig. 現(xiàn)在的替代者為php-fpm(FastCGI Process Manager).

    看下php-fpm的配置。 在服務(wù)器上,放一腳本文件,內(nèi)容:

    <?php phpinfo(); ?>

    輸出:

    ... Server API	FPM/FastCGI Virtual Directory Support	disabled Configuration File (php.ini) Path	/etc/php7 Loaded Configuration File	/etc/php7/php.ini Scan this dir for additional .ini files	/etc/php7/conf.d ...

    說(shuō)明配置文件為 /etc/php7/php.ini的/etc/php7/conf.d

    再看下cli模式的配置文件. 運(yùn)行

    php -r "phpinfo();"

    -r 即 run運(yùn)行全集意思. 輸出為:

    ... Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/7.0/cli Loaded Configuration File => /etc/php/7.0/cli/php.ini Scan this dir for additional .ini files => /etc/php/7.0/cli/conf.d Additional .ini files parsed => /etc/php/7.0/cli/conf.d/10-opcache.ini, ...

    配置文件路徑為: /etc/php/7.0/cli/php.ini 和php-fpm是不同的。

    常聽(tīng)到有人說(shuō),php只能作為服務(wù)器暫時(shí)間腳本,不能作為長(zhǎng)時(shí)間工作,還有安全配置會(huì)影響命令行等,顯然是錯(cuò)誤的。

    其它差異

    cli模式,定義了STDIN, STDOUT, STDERR三個(gè)常量; 如: $stderr = fopen(‘php://stderr’, ‘w’);

    CLI SAPI 不會(huì)將當(dāng)前目錄改為已運(yùn)行的腳本所在的目錄.

    php作為shell腳本

    有兩種方法將php腳本作為shell腳本, 如腳本:
    hello.php

    <?php echo "hello world!"; var_dump($argv); ?>

    方法1, php 腳本 參數(shù)

    ~php hello.php -s 'me' hello world array(3) {   [0]=>   string(9) "hello.php"   [1]=>   string(2) "-s"   [2]=>   string(2) "me" }

    方法2, 在php文件頭加

    #!/usr/bin/php

    然后 chmod u+x hello.php
    執(zhí)行 ./hello.php

    hello world array(1) {   [0]=>   string(11) "./hello.php" }

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)