cURL Download Progress in PHP not working?

后端 未结 2 1796
时光取名叫无心
时光取名叫无心 2021-01-01 04:18

I am a PHP newbie and trying to add a progress-bar to an existing PHP script using the following method :

$ch=curl_init() or die(\"ERROR|Error:

        
相关标签:
2条回答
  • 2021-01-01 05:08

    Regarding the last comment, said code requires 5.3 because stream_context_create()'s second parameter was added in 5.3. However, replacing that line with the following works in 5.2:

    $ctx = stream_context_create();
    stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
    

    And in related news, the stream_notification_callback() documentation within the PHP manual has an example that fully utilizes/creates a progress bar, so check it out.

    http://php.net/stream_notification_callback

    0 讨论(0)
  • 2021-01-01 05:14

    There doesn't seem to be a CURLOPT_PROGRESSFUNCTION before php 5.3.

    Take a look at http://cvs.php.net/viewvc.cgi/php-src/ext/curl/interface.c?view=log and you will find two entries - [DOC] MFH: #41712, implement progress callback. One for the php5.3 and one for the php6 branch.

    edit: With php 5.2.x you should be able to set a stream_notification_callback

    function foo() {
      $args = func_get_args();
      echo join(', ', $args), "\n";
    }
    
    $ctx = stream_context_create(null, array('notification' =>'foo'));
    $fpIn = fopen('http://php.net/', 'rb', false, $ctx);
    file_put_contents('localfile.txt', $fpIn);
    
    0 讨论(0)
提交回复
热议问题