17
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2013-12-26

デバッグのためにターミナルから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

17
15
2

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
  3. You can use dark theme
What you can do with signing up
17
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?