0

I'm using this tiny PHP code in order to mirror any files into my server.

<?php
 $cmd= "curl -L -O http://www.dropbox.com/s/8lu0nutt4tgpkku/jbtools.ipa";
 exec($cmd);
?>

But the browser is freezing until the mirroring process gets finished. My question is that how can I display the progress bar like when I run this command in Terminal. something like this:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed

I tried many flags such as:

-v --verbose -I -include --trace -

but none of them worked. I also asked a question here to convert it to a PHP CURL code but no one could help me with that!

If it's not possible, it's really appreciated advising me to do the same job by any other commands.

Community
  • 1
  • 1
PersianHero
  • 87
  • 2
  • 10
  • Use ob_flush() to send data to browser before loading content is finished, alternatively, you could write the status into a session and access it trough another page. See php.net for a real php curl function. Your code is more a workaround and not good if you want to work with it in php – Jonas Wilms Aug 13 '16 at 15:25
  • I did try cURL but I got stuck at a point but no one could help me! Can u have a look pleae? http://stackoverflow.com/questions/38427001/how-can-i-convert-this-curl-command-to-php – PersianHero Aug 13 '16 at 21:38
  • The code looks fine. I cannot find adcdownload.com. – Jonas Wilms Aug 14 '16 at 09:45
  • That link is no longer valid. Just updated the post;check it out pls. BTW, I'm using "-b cookies.txt" for Apple developer portal(for authentication) so as the new link is a Dropbox link, I think we don't need to have this flag! – PersianHero Aug 14 '16 at 13:22
  • As i already told you, i cannot find any mistake. Whats the error the code trows? – Jonas Wilms Aug 14 '16 at 13:26
  • Just UPDATED the first post of that topic along with the link of the code. Can u check it out and advise me from that topic pls. – PersianHero Aug 14 '16 at 15:18

1 Answers1

0

Easiest way is by polling. Execute the script in the background and direct the output (to a file) that your frontend (js) can poll.

execute in the background with examples: https://felixmilea.com/2014/12/running-bash-commands-background-properly/

showing progress in the shell can be done with piping to pv: http://linux.die.net/man/1/pv

consider trying this with websockets: http://reactphp.org/ - look at the rachet project. this will give you realtime output of whatever you want to execute.

visualex
  • 736
  • 12
  • 17