I’m using exec to grab curl output (I need to use curl as linux command).
When I start my file using php_cli I see a curl output:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 75480 100 75480 0 0 55411 0 0:00:01 0:00:01 --:--:-- 60432
It means that all the file has been downloaded correctly (~ 75 KB).
I have this code:
$page = exec('curl http://www.example.com/test.html');
I get a really strange output, I only get: </html>
(that’s the end of my test.html file)
I really do not understand the reason, CURL seems to download all the file, but in $page I only get 7 characters (the lastest 7 characters).
Why?
P.S. I know I can download the source code using other php functions, but I must to use curl (as linux command).
Unless this is a really weird requirement, why not use PHP cURL library instead? You get much finer control on what happens, as well as call parameters (timeout, etc.).
If you really must use curl command line binary from PHP: