ITNC
asked on
PHP setCookie inside Curl Progress Function
Currently I have a progress function Curl is using to write the current progress to a txt file. From there I have Jquery doing an ajax GET to get the current progress of the download. This all is working properly but I want to move from using a file to using a cookie and then have jquery read that cookie instead of working with actual files. Right now I modified the progress callback function to use setcookie but I am seeing an issue that is breaking things on the jquery end of things. I see where the cookie is being set but it doesn't get updated again until the progress is 100. So basically the progress cookie jumps from 0 to 100 percent and is not representative of the actual progress. Here is that function as it is now (you can see in the commented code where I was writing to a file:
function progressCallback($resource, $download_size, $downloaded_size, $upload_size, $uploaded_size)
{
global $workingDir;
static $previousProgress = 0;
if ($download_size == 0) {
$progress = 0;
} else {
$progress = round($downloaded_size * 100 / $download_size);
if ($progress > $previousProgress) {
$previousProgress = $progress;
//$fp = fopen($workingDir.'progress.txt', 'w');
//fputs($fp, "$progress");
//fclose($fp);
setcookie('progressPercent', $progress, 0, '/', '', 0, 0);
}
}
}
greetings ITNC, , you are using php to "SET" a cookie here, , however, your problem may be that the browser, is not periodically "READING" this cookie and updating the the percentage display. you used to use a periodic "Ajax" file retrieve to update the percentage, , in what kind of repeating process in the javascript of the browser, are you reading the cookie "progressPercent" to update the display?
ASKER
I am using the jquery cookie plugin inside a function that is called using setInterval
This is how I am reading the cookie currently each time the function executes.
percentage = $.cookie("progressPercent");
This is how I am reading the cookie currently each time the function executes.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was thinking the same thing unfortunately. I will consider the $_SESSION approach but I'm thinking I'll just stick with the file method for now. My research ended in the same conclusion so I feel verified now, I will mark that as the answer thanks for your time!