cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: If statements inside PHP Curl Writefunction

From: Jake Cattrall <contact_at_websiteforge.co.uk>
Date: Mon, 6 Aug 2012 18:33:55 +0100

After a careful look through, I found the issue is more complex.

This code works but imagine that I am using content-disposition and
forwarding this file to the user...

<?php
function bytesize($chunksize){
static $downloaded = 0;
$downloaded += $chunksize;
return $downloaded;
}

$writefn = function($ch, $chunk) {
  $chunksize = strlen($chunk);
  bytesize($chunksize);
  return $chunksize;
};

$ch = curl_init("http://cachefly.cachefly.net/100mb.test"); //init
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $writefn); // set write function
curl_exec($ch); //exec
curl_close(); // close
echo bytesize(0); // after server has finished downloading, echo the
downloaded size.
?>

As far as curl is concerned, everything is run correctly.

Because it is streaming the file, the server first downloads the full file,
in my case I am downloading the file using a download manager, the first
connection from the download manager does not request partial content but
the full file, yet only intends to download a part of it.

For instance, the download manager is using 4 connections to download a
10mb file. The first connection asks for the full file and stops
downloading when 2.5mb has been downloaded. Of course, by this time the
server has downloaded the full file and that is why I am getting a
miscalculated total in my database.

Do you have any suggestion of how to deal with this?

On 6 August 2012 16:39, <curl-and-php_at_latter.org> wrote:

> 06/08/12 16:33, Jake Cattrall wrote:
>
>> Thanks that did help, it is now calculating all the way to the end,
>> however there is some strange math going on here. I downloaded a 300mb
>> file and the reported size is 500mb?
>> I've tried this various ways now, calculating results as bits and bytes
>> and it refuses to come out correct.
>>
>> I'm gonna cut my losses and presume this functionality is not available
>> in curl.
>>
>
> Want to show your code? I don't see why it shouldn't work, in principle.
> ______________________________**_________________
> http://cool.haxx.se/cgi-bin/**mailman/listinfo/curl-and-php<http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php>
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2012-08-06