LoginSignup
16

More than 5 years have passed since last update.

posted at

updated at

コマンドライン上からPHPスクリプトに$_GETを渡す

デバッグのためにターミナルからPHPのスクリプトにGETリクエストの変数を渡したいことがたまにある.
調べてみたらphp-cgiなるものをインストールすると幸せになれるらしいのでやってみた.

Ubuntu(-14.04)

$ sudo apt-get install php-cgi

Ubuntu(14.10)

$ sudo apt-get install php5-cgi

Arch Linux

$ yaourt -S php-cgi

軽くテスト

test.php
<?php
print_r($_GET);
$ php-cgi test.php hoge=fuga foo=bar num=1
X-Powered-By: PHP/5.3.10-1ubuntu3.9
Content-type: text/html

Array
(
    [test_php] =>
    [hoge] => fuga
    [foo] => bar
    [num] => 1
)

参考:
http://serverfault.com/questions/187025/how-to-pass-get-variables-to-a-php-script-via-the-command-line/187038#187038

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
16