【PHP命令行参数详解及应用_php技巧】教程文章相关的互联网学习教程文章

如何在PHP中解析命令行参数?【代码】

我从命令行调用PHP脚本$php my_script.php –num1 = 124 –first_name = don 如何访问传递到此脚本的任何键值对?键可以是任意的,因此使用具有特定值的getopt()将不起作用. 这是我想在我的脚本中访问的内容:$my_args = array("num1" => 124,"first_name" => "don" );如果我使用var_dump($argv),我得到这个输出:array([0] => "my_script.php",[1] => "--num1=5",[2] => "--num2=123" );我应该看看解决方法: $my_args = array(); f...

php的命令行选项解析,howto【代码】

我在PHP 5.2中使用Console_Getopt,并且发现它与其他语言中的getopt有多么不同(perl,bash,java).任何人都可以推荐如何解析返回的数组“$opts”中的args? php myprog.php -a varA -c -b varB$o= new Console_Getopt; $opts = $o->getopt($argv, "a:b:c"); print_r($opts);// print_r返回下面Array ([0] => Array([0] => Array([0] => a[1] => varA)[1] => Array([0] => c[1] =>)[2] => Array([0] => b[1] => varB))[1] => Array())我...

php – 如何使用命令行手动运行laravel / lumen作业【代码】

我在app / Jobs / MyJob.php文件夹中创建了一个Job文件,如果可以使用命令行,我想只运行一次. 就像是: &GT php MyJob:运行 我应该使用什么命令来运行此文件或句柄中的方法?解决方法:跑php artisan make:command DispatchJob创建运行工作的特殊工匠命令. 打开创建的DispatchJob.php文件并定义DispatchJob类,如下所示:class DispatchJob extends Command {/*** The name and signature of the console command.** @var string*/pr...

无法从命令行运行phpunit测试【代码】

我正在尝试使用phpunit框架在新的laravel 5应用程序中运行单元测试.在我的laravel应用程序的根路径中,我使用以下命令:./vendor/bin/phpunit /tests/ExampleTest.php然后我收到以下消息:You need to set up the project dependencies using the following commands: wget http://getcomposer.org/composer,phar php composer.phar install我已经在may系统中安装了composer,我使用composer安装了Laravel 5.我安装新的laravel 5应用...

使用Mac上命令行中的zend服务器附带的php

我已经在我的mac上安装了zend服务器,我认为我的mac上有两个安装的php(我讨厌mac,顺便说一句,我很想回到Windows 7),我认为我正在运行的脚本命令行(phpcs)正在使用/usr/bin /中的php命令,而我想使用/usr/local/zend / bin / always中的那个.我该怎么做?解决方法:在/usr/bin之前将/usr/local/zend / bin添加到PATH. 或者只是在/usr/bin中卸载PHP.

停止运行PHP服务器,命令行【代码】

所以我已经完成了php -S localhost:8000,但我不再需要它,我需要我的8000本地主机.如何停止php服务器?解决方法: PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011 Listening on localhost:8000 Document root is /home/me/public_html Press Ctrl-C to quit.如果您没有打开该终端,则必须找到该进程的PID并将其终止. 要找到PID并终止进程,here is a nice explanation.

PHP cli命令行safe_mode限制【代码】

我正在使用Kohana框架(3.0.9),它生成每日日志.我希望邮寄日志文件,如果在CRON运行脚本的前一天发送了一个日志文件,但经过几天的尝试,我无法弄清楚如何在PHP CLI模式中推迟safe_mode. 当我在网上运行我的脚本时,没有问题.但我想在我的Plesk 9.5.2服务器上运行脚本作为CRON任务(或以root用户身份在命令行上运行)我收到以下错误:ErrorException [ 2 ]: dir(): SAFE MODE Restriction in effect. The script whose uid is 10001 is n...

pg_connect – php脚本可以从命令行运行,但不能从网页运行【代码】

我有一个CentOS apache web服务器,我已经设置了访问我们的数据库服务器(也是CentOS).数据库服务器上的pg_hba.conf中有一个Web服务器条目.我可以在运行Web服务器的机器的命令行(使用bash下的“php -a”)上无问题地连接.这是我的脚本(凭据损坏)if(pg_connect("host=192.168.6.11 port=5432 dbname=C_test user=Cuser password=c1811wet")) { echo 'connected'; } else { echo 'not'; }从命令行运行此脚本时,我得到“连接”.当我作为...

php – 为什么我的单元测试通过Hudson / Phing失败,但是在命令行上通过Phing成功?【代码】

基本信息: PHP 5.3.3PHPUnit 3.4Zend Framework 1.10.8 Phing构建目标<target name="test"><echo msg="PHPUnit..." /><phpunit codecoverage="false" haltonfailure="true" haltonerror="true" printsummary="true" bootstrap="${testdir}/application/bootstrap.php"><batchtest><fileset dir="${testdir}"><include name="**/*Test.php" /><exclude name="./application/ControllerTestCase.php" /><exclude name="./applicatio...

使用PHP中的exec()发出HTTPS SVN命令行请求【代码】

我已经创建了一个命令,它对存储在托管SVN服务上的SVN存储库进行信息调用.这是一个例子:exec('svn info https://myrepo.svn.beanstalkapp.com/project/name/folder 2>&1', $output, $returnStatus); if ($returnStatus) {print_r($output); }我得到的回应是:Array ([0] => Authentication realm: SVN[1] => Password for 'apache': Authentication realm: SVN[2] => Username: svn: PROPFIND request failed on '/project/name/...

加载xdebug时,CakePHP命令行不起作用【代码】

我正在尝试使用xdebug对PHP 7.1.6来解决我的CakePHP v3.3.6项目中的失败单元测试问题.我使用以下设置设置了xdebug:[xdebug] xdebug.remote_enable = on xdebug.remote_host = 127.0.0.1 xdebug.remote_port = 9000 xdebug.remote_autostart = 1 xdebug.profiler_enable = off xdebug.profiler_enable_trigger = off xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir = "c:/wamp/tmp" xdebug.show_...

知道为什么我可以从命令行执行命令而不是从PHP执行命令exec()【代码】

好, 我做了一些创造性的搜索,并且有点像路障. 我正在尝试使用linux程序“sox”.我试图从我的PHP脚本中调用它.如果我使用命令行,脚本可以工作.但是,当我使用PHP exec时,它不起作用. 例:sox file1.mp3 file2.mp3 tempfile.mp3 -V3(“V3”指定详细输出) 当在命令行中以“User X”或root身份执行时,我可以创建新文件.但是,当我执行命令时:<?php exec('sox file1.mp3 file2.mp3 tempfile.mp3 -V3', $output); foreach($output as $li...

VIM:在命令行中显示PHP函数/类?【代码】

有没有办法在VIM命令行中显示当前的PHP函数或类名?我找到了一个显示C function names in the status line的插件,但它不适用于PHP,无论如何我更喜欢使用命令行来节省宝贵的垂直线. 谢谢.解决方法:编辑 在寻找TagList帮助中完全不相关的东西时,我刚刚找到了这两个函数:Tlist_Get_Tagname_By_Line() Tlist_Get_Tag_Prototype_By_Line()在我的状态栏中添加它可以很好地工作:%{Tlist_Get_Tagname_By_Line()}另外,你读过Vim Wiki吗?它...

将数据放入php://从命令行输入【代码】

我有一个PHP脚本从php://输入读取.使用我的命令行,我可以运行脚本,但我不知道如何“填充”php://输入. 我尝试使用php file.php< my_test_data但它填充了php:// stdin而不是php://输入该脚本可以概括为: <?php echo file_get_contents('php://input'); ?>解决方法:php://输入仅适用于从Web服务器运行的脚本. 当CLI脚本需要访问标准输入时,它们使用php:// stdin或已打开的流STDIN:<?php echo file_get_contents('php://stdin...

命令行 – PHP命令行php.ini路径错误【代码】

我试图在命令行上运行一些PHP页面但是遇到了一些mysql和其他PHP扩展的问题. 运行php –ini会产生以下输出:Configuration File (php.ini) Path: /usr/local/lib Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none)当我在命令行上运行php时,它无法找到我的php.ini文件.这是因为路径不正确.我的php.ini实际上位于/etc/php.ini中,如我的phpinfo()中所述...

命令行参数 - 相关标签