Reputation: 329
This is probably the opposite of what is usually asked, but is there anyway to actually make a cURL request slower and make the loading process last longer? I've searched and couldn't find any solutions. Thanks for your help!
Upvotes: 3
Views: 2536
Reputation: 304
try CURLOPT_MAX_RECV_SPEED_LARGE, to slow down the transfer
curl_setopt($cSlow,CURLOPT_MAX_RECV_SPEED_LARGE,10)
It will work only with PHP 5.4
ps.Sorry the poor enlgish
Upvotes: 6
Reputation: 6517
You can add a usleep in the curl progress function, if you really need to hack a slow transfer:
<?php
/* fast curl */
$cFast = curl_init('http://stackoverflow.com/users/2779152/madebydavid');
curl_setopt($cFast, CURLOPT_RETURNTRANSFER, true);
$time = microtime(true);
$result = curl_exec($cFast);
echo("fast: ".(microtime(true) - $time)."\n");
/* slow curl */
$cSlow = curl_init('http://stackoverflow.com/users/2779152/madebydavid');
curl_setopt($cSlow, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSlow, CURLOPT_NOPROGRESS, false);
curl_setopt($cSlow, CURLOPT_PROGRESSFUNCTION, function() {
usleep(100000);
return 0;
});
$time = microtime(true);
$result = curl_exec($cSlow);
echo("slow: ".(microtime(true) - $time)."\n");
The first request is fast, the second slow - if you save it as curlFastSlow.php then run it, the second request should have a noticeable difference:
$ php -q curlFastSlow.php
fast: 0.58203315734863
slow: 1.5010859966278
Upvotes: 5