【发布时间】:2015-10-28 21:08:41
【问题描述】:
proc_open() 出于安全原因已被禁用
我目前正在免费托管 (Hostinger) - 制作个人网站仅供我和其他一些人使用。
我知道我应该从 php.ini 中删除 proc_open,但由于我的共享主机计划,我无法访问它。
我的代码中围绕proc_open 的代码如下 - 如果您需要完整代码,请告诉我。我试过注释掉部分,但它返回错误。
我只想删除它并让代码正常运行。
<?php
// Initializing
if (!isset($ACCOUNTS)) $ACCOUNTS = array();
if (isset($USER) && isset($PASSWORD) && $USER && $PASSWORD) $ACCOUNTS[$USER] = $PASSWORD;
if (!isset($HOME_DIRECTORY)) $HOME_DIRECTORY = '';
$IS_CONFIGURED = count($ACCOUNTS) >= 1 ? true : false;
// Command execution
function execute_command($command) {
$descriptors = array(
0 => array('pipe', 'r'), // STDIN
1 => array('pipe', 'w'), // STDOUT
2 => array('pipe', 'w') // STDERR
);
$process = proc_open($command . ' 2>&1', $descriptors, $pipes);
if (!is_resource($process)) die("Can't execute command.");
// Nothing to push to STDIN
fclose($pipes[0]);
$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$error = stream_get_contents($pipes[2]);
fclose($pipes[2]);
// All pipes must be closed before "proc_close"
$code = proc_close($process);
return $output;
}
【问题讨论】:
-
简单的答案是删除整个函数
execute_command。在 Hostinger 的免费帐户上,您无权运行 shell 命令,并且可能永远不会被允许这样做 -
是的,谢谢,我将在完成工作后搬到新的主机上。所以我可以删除整个命令,它会起作用吗?非常感谢。
-
我不确定脚本是否会运行,如果它需要运行 shell 脚本...
-
为什么你甚至需要在个人网站上运行 shell 命令?
-
你们是如何解决这个问题的?
标签: php