command-line-interface

Set $_SERVER variable when calling PHP from command line?

守給你的承諾、 提交于 2019-11-28 22:21:29
问题 Is it possible to pass a $_SERVER variable to a PHP script via the command line? Specifically I am trying to set the $_SERVER['recipient'] manually so I can test email piping without setting up a mail server. 回答1: On *nix: $ recipient="email@domain.com" php script.php <?php print_r($_SERVER); Test: $ recipient="email@domain.com" php script.php | grep recipient [recipient] => something@domain.com Or, you can export it or setenv (depending on your OS), like $ export recipient="email@domain.com"

PHP Server Name from Command Line

北战南征 提交于 2019-11-28 21:05:34
Is there a way to detect the name of the server running a PHP script from the command line? There are numerous ways to do this for PHP accessed via HTTP. But there does not appear to be a way to do this for CLI. For example: $_SERVER['SERVER_NAME'] is not available from the command line. echo php_uname("n"); see http://php.net/manual/en/function.php-uname.php Alexander V. Ilyin <?php echo gethostname(); // may output e.g,: sandie See http://php.net/manual/en/function.gethostname.php gethostname() is a convenience function which does the same as php_uname('n') and was added as of PHP 5.3 The

Commons CLI required groups

不羁岁月 提交于 2019-11-28 20:14:49
I am writing command line application in Java and I've chosen Apache Commons CLI to parse input arguments. Let's say I have two required options (ie. -input and -output). I create new Option object and set required flag. For now it's all good. But I have third, not required option , ie. -help. With settings that I've mentioned, when user wants to show help (use -help option) it says "-input and -output" are required. Is there any way to implement this (via Commons CLI API, not simple if (!hasOption) throw new XXXException()). Emmanuel Bourg In this situation you have to define two sets of

SIP-Client for Raspberry Pi that works from command line?

蹲街弑〆低调 提交于 2019-11-28 18:58:10
i want to use my raspberry pi as a SIP/VOIP-Phone, just controlling the RPI via SSH. I found some tutorials and it seems that Twinkle is one of the most useful apps for that. So i successfully installed twinkle on my RPI, one SPI-Client on my Android-Phone and for know i am able to send text messages from one to another. The thing is: I have to use the Twinkel GUI with X-Server-forwarding (currently using MacOS with X11 and iTerm). But i kind of want to automate the whole process, like using twinkle from command line, controll it with scripts etc. So, obviously twinkle is not made for that.

Create cronjob with Zend Framework

China☆狼群 提交于 2019-11-28 18:19:50
I am trying to write a cronjob controller, so I can call one website and have all modules cronjob.php executed. Now my problem is how do I do that? Would curl be an option, so I also can count the errors and successes? [Update] I guess I have not explained it enough. What I want to do is have one file which I can call like from http://server/cronjob and then make it execute every /application/modules/*/controller/CronjobController.php or have another way of doing it so all the cronjobs aren't at one place but at the same place the module is located. This would offer me the advantage, that if a

Use different PHP version CLI executable for one command

醉酒当歌 提交于 2019-11-28 18:13:07
So I have Gentoo box with three PHP versions installed (nevermind the reasons): /usr/bin/php -> /usr/lib64/php5.4/bin/php /usr/bin/php5.5 -> /usr/lib64/php5.5/bin/php /usr/bin/php5.6 -> /usr/lib64/php5.4/bin/php I want to install Laravel framework using composer: $ composer create-project laravel/laravel --prefer-dist This however throws an error because Laravel requires PHP > 5.5.9 and the default php interpreter is 5.4 . So I issue another command: $ /usr/bin/php5.6 /usr/bin/composer create-project laravel/laravel --prefer-dist This takes me one step further, but then some post-install

How do I identify the particular Linux flavor via command line?

丶灬走出姿态 提交于 2019-11-28 18:12:12
I'd like to be able to detect which particular Linux flavor is installed on a computer, e.g. Ubuntu vs Fedora, via a command line command. Some people recommend uname -a , but that only reports the kernel version. Try the below command.... It worked for me... cat /proc/version Once you know that you are running Red Hat for example, you can get to the point with: cat /etc/redhat-release Or on Debian: cat /etc/debian_version or in general : cat /etc/*-release Also you could use the following command cat /etc/issue For displaying details including release and codename of the distro lsb_release -a

PHP CLI won't log errors

霸气de小男生 提交于 2019-11-28 17:47:29
PHP currently will not log errors produced from the command line. I have : log_errors = On error_log = /var/log/php_errors.log in /etc/php5/cli/php.ini Am I missing a further setting to get this working? George Cummins Please check that the user account running PHP CLI has write access to /var/log/php_errors.log . Additionally, you can verify that you are using the correct php.ini file like this: php -a -c /etc/php5/cli/php.ini This question and answer thread was very helpful to me while setting up PHP CLI logging on an Ubuntu 12.04 environment, so I wanted to post an answer that distills what

Parsing arguments to a Java command line program

狂风中的少年 提交于 2019-11-28 17:25:14
What if I wanted to parse this: java MyProgram -r opt1 -S opt2 arg1 arg2 arg3 arg4 --test -A opt3 And the result I want in my program is: regular Java args[] of size=4 org.apache.commons.cli.Options[] of size=3 org.apache.commons.cli.Options[] #2 of size=1 I would prefer to use Apache Commons CLI , but the documentation is a little unclear about the case I present above. Specifically, the documentation doesn't tell you how to handle options of the 3rd type I specify below: 1. options with a "-" char 2. options with a "--" char 3. options without any marker, or "bare args" I wish that Apache

Custom tab completion in python argparse

徘徊边缘 提交于 2019-11-28 17:05:52
问题 How to get shell tab completion cooperating with argparse in a Python script? #!/usr/bin/env python import argparse def main(**args): pass if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('positional', choices=['spam', 'eggs']) parser.add_argument('--optional', choices=['foo1', 'foo2', 'bar']) args = parser.parse_args() main(**vars(args)) With an executable flag set on the .py file, the expected results should be something like: $ ./example.py sp<tab> ->