<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

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

    時間:2025-01-15 11:58:26 php語言 我要投稿

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

      最近迷上了php腳本,整天滿腦子都是php.也用php寫了一些腳本,甚至服務來完成一些日常服務器管理的任務,下面小編就給大家介紹下Unix/Linux中如何直接執行PHP腳本文件。

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

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

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

      編寫你的腳本文件

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

      Here is some plain text.

      Here is the file name:

      <?php

      echo $argv[0],PHP_EOL;

      ?>

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

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

      yuanyu@ymac:phpworkspace $phptest_run.phphello

      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腳本文件的操作方法,不熟悉的用戶可以參照上面介紹的具體步驟來操作。

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

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

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

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

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

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

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

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

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

    php文件怎么上傳06-21

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人