在php返回垃圾(HTTP响应)中执行exec(‘php -v’)时出错
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在php返回垃圾(HTTP响应)中执行exec(‘php -v’)时出错,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2869字,纯文字阅读大概需要5分钟。
内容图文
![在php返回垃圾(HTTP响应)中执行exec(‘php -v’)时出错](/upload/InfoBanner/zyjiaocheng/803/1381402bbb614219b481a16d34ca4d0f.jpg)
我有一个共享服务器Linux,我面临一个奇怪的问题.我试图通过PHP执行以下命令,它运行正常;给我返回PHP安装路径/usr/bin/php.
exec('which php');// This runs so exec is not disabled
但是我尝试用exec执行的任何命令(‘php …’);没有随机返回一个98到114个元素的数组,几乎全部都是垃圾.我跑的命令的例子是……
exec('php -v');
exec('php -i');
exec('/usr/bin/php -v');
以上都没有返回合理的东西.知道为什么php运行的任何命令没有执行?
下面是exec()返回给我的数据数组的var_dump().
编辑(更多RND之后)
我能够执行
exec('php -h')
它以可读格式重新表达了以下数组.
string(9) "php -help"
string(47) "Usage: php [-q] [-h] [-s] [-v] [-i] [-f ]"
string(27) " php [args...]"
string(36) " -a Run interactively"
string(69) " -b | Bind Path for external FASTCGI Server mode"
string(57) " -C Do not chdir to the script's directory"
string(58) " -c | Look for php.ini file in this directory"
string(47) " -n No php.ini file will be used"
string(56) " -d foo[=bar] Define INI entry foo with value 'bar'"
string(70) " -e Generate extended information for debugger/profiler"
string(46) " -f Parse . Implies `-q'"
string(28) " -h This help"
string(34) " -i PHP information"
string(43) " -l Syntax check only (lint)"
string(43) " -m Show compiled in modules"
string(60) " -q Quiet-mode. Suppress HTTP Header output."
string(60) " -s Display colour syntax highlighted source."
string(33) " -v Version number"
string(72) " -w Display source with stripped comments and whitespace."
string(46) " -z Load Zend extension ."
string(75) " -T Measure execution time of script repeated times."
This page was created in 0.055487155914307 seconds
哦,顺便说一下我用来测试的脚本是以下……
<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
if(!empty($_GET['p']) && $_GET['p'] == true){
//$command = 'php -help'; //this works
//$command = 'cat ' . getcwd() . '/dummy1.txt'; //this works echo's a simple text file
//$command = 'php -q ' . getcwd() . '/dummy1.txt'; //NOT WORKING
$command = 'php -m'; //NOT WORKING
echo '<div><pre>';
var_dump($command);
echo '</pre></div>';
exec($command, $output, $return);
//passthru($command,$output);
echo '<div><pre>';
foreach($output as $key => $value){
var_dump($output[$key]);
}
echo '</pre></div>';
}
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "This page was created in ".$totaltime." seconds";
?>
解决方法:
它的PHP CGI从环境中读取脚本名称,从而导致调用脚本运行多次或有时无限次.
解决方案是使用命令php-cli而不是命令php.
替换行$command =’php -m’; with $command =’php-cli -m’;在你的代码上,一切都会正常工作.
内容总结
以上是互联网集市为您收集整理的在php返回垃圾(HTTP响应)中执行exec(‘php -v’)时出错全部内容,希望文章能够帮你解决在php返回垃圾(HTTP响应)中执行exec(‘php -v’)时出错所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。