PHP 上的 shell_exec 和 exec 没有返回字符串

3 php apache shell

我对这段代码感到头疼:

$data = shell_exec("wget -S --spider http://dkphp.com");
echo "Encoded:" .$data;
Run Code Online (Sandbox Code Playgroud)

$数据为“NULL”

我不知道为什么,它支持 echo 之类的东西:( 今天花了大约 5 个小时,它仍然是 NULL :(

HTTP request sent, awaiting response...
  HTTP/1.0 200 OK
  Date: Thu, 29 Sep 2011 01:31:45 GMT
  Server: LiteSpeed
  Connection: close
  X-Powered-By: PHP/5.3.8
  Set-Cookie: PHPSESSID=50781d657c7632cc1b2e7536d5fa0c50; path=/
  Expires: Thu, 19 Nov 1981 08:52:00 GMT
  Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
  Pragma: no-cache
  content: text/html
  Content-Type: text/html
Length: unspecified [text/html]
200 OK
Run Code Online (Sandbox Code Playgroud)

MrT*_*ick 5

我在 PHP 的交互模式下检查了你的代码片段(php -a从命令行)

wget 将该信息打印到 STDERR,而不是 STDOUT。

这有效:

$data = shell_exec("wget -S --spider http://dkphp.com 2>&1");
echo "Encoded:" .$data;
Run Code Online (Sandbox Code Playgroud)