3

I got headache by this code:

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

$data is "NULL"

I don't know why, its support to echo something like :( Spend like 5 hours today, and its still 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
1
  • Are you running PHP in safe mode? The command is disable if running under safe mode according to the PHP manual Commented Sep 29, 2011 at 1:38

1 Answer 1

5

I checked your code snippet in PHP's interactive mode (php -a from the command line)

wget prints that information to STDERR, not STDOUT.

This works:

$data = shell_exec("wget -S --spider http://dkphp.com 2>&1");
echo "Encoded:" .$data;
Sign up to request clarification or add additional context in comments.

2 Comments

thanks guys. Can you send me any link to learn about STDERR and STDOUT ?
You may find this article helpful: en.wikipedia.org/wiki/Standard_streams . Also, there are standard ways to redirect streams around in a linux shell. This one explains what I've suggested above, in that the STDERR stream is redirected to the STDOUT stream. (where shell_exec reads it) cyberciti.biz/faq/redirecting-stderr-to-stdout

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.