简体   繁体   中英

How to hidden the output of Linux command launched from shell_exec()

Hi guys this is my code

<?php
  $res = shell_exec('curl  http://www.example.com');

I launched it from the terminal using this command

php script.php

and this is the output:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  1270  100  1270    0     0   5515      0 --:--:-- --:--:-- --:--:-- 11545

I don't want to see nothing how can i do??

You are seeing that output because curl outputs its current progress to STDERR.

You could solve this with a redirection if you want to ignore it:

$res = shell_exec('curl  http://www.example.com 2>/dev/null');

Or, in the shell level:

$ php script.php 2>/dev/null

You can use output buffering

ob_start();
$res = shell_exec('curl  http://www.example.com');
ob_end_clean();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM