<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
            php語言

            Unix/Linux中怎么直接執行PHP腳本文件

            時間:2025-02-15 21:04:50 php語言 我要投稿
            • 相關推薦

            Unix/Linux中怎么直接執行PHP腳本文件

              使用Linux系統的服務器都有搭建完整的PHP環境,因此有些用戶會用PHP去寫一些執行自動化任務的腳本,可是發現每次執行PHP腳本都需要使用php myscript.php的方式,感覺有點麻煩。其實我們是可以直接執行PHP腳本文件的下面小編給大家整理了,供大家參閱。

              由于我們的服務器都是使用的 Linux 系統,并且都有搭建完整的 PHP 環境,所以有時候我會用 PHP 寫一些執行自動化任務的腳本,但是每次執行這個 PHP 腳本都需要使用 php myscript.php 的方式,

              編寫你的腳本文件

              這里我們編寫一個名字為 test_run.php 的文件,文件的內容如下:

              Here is some plain text.

              Here is the file name:

              <?php

              echo $argv[0], PHP_EOL;

              ?>

              腳本內容很簡單,就是把當前腳本文件的名稱打印出來。

              然后,我們使用 PHP 命令執行一下這個腳本:

              yuanyu@ymac:phpworkspace $ php test_run.php hello

              Here is some plain text.

              Here is the file name:

              test_run.php

              yuanyu@ymac:phpworkspace $

              給腳本文件增加頭信息,并且設置權限

              然后,在這個文件的第一行寫上 php 命令的全路徑,前面是一個 #!:

              #!/usr/bin/php

              Here is some plain text.

              Here is the file name:

              <?php

              echo $argv[0], PHP_EOL;

              ?>

              然后給這個文件賦予可執行的權限:

              yuanyu@ymac:phpworkspace $ chmod u+x ./test_run.php

              接下來就可以直接執行這個腳本了:

              yuanyu@ymac:phpworkspace $ ./test_run.php

              Here is some plain text.

              Here is the file name:

              ./test_run.php

              yuanyu@ymac:phpworkspace $

              這種方式在 PHP 官方文檔中也是有說的,請參考:

              http://php.net/manual/en/features.commandline.usage.php

              文檔中的

              “Example #2 Script intended to be run from command line (script.php)”

              以上就是Unix/Linux中直接執行PHP腳本文件的操作方法,不熟悉的用戶可以參照上面介紹的具體步驟來操作。

            【Unix/Linux中怎么直接執行PHP腳本文件】相關文章:

            Linux怎么直接執行PHP腳本文件08-05

            PHP腳本修改Linux或Unix系統口令方法05-01

            linux系統怎么添加計劃任務執行php文件07-20

            怎么在linux的CLI下運行php文件05-26

            PHP怎么執行Linux系統命令函數08-10

            在UNIX或Linux中TTY的意思04-25

            PHP腳本修改Linux系統口令的方法05-11

            如何打開php文件 php文件怎么打開01-13

            linux下執行java程序的sh腳本教程08-15

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院