I have download products and the counter for number of downloads is not incrementing as it should. When I click on the file to inititate the download, it increments up one as one might expect, but after the download is complete and one refreshes the page, the counter goes back to the number that was there before--thus, the new count is not being added to the "accessed" field in the uc_file_users table.

This worked fine for me in Drupal 5 version of Ubercart. I've tried both the release and Dev version of the program.

Any thoughts as to what I might try?

Of course if I edit the uc_file_users table and change the count in the database, then the new count will show in my downloads table on the website. But we want to be able to restrict the number of downloads and IPs right?

Can someone else see if this does/does not work for them?

Thanks so much.

Dan

Comments

royerd’s picture

On further investigation, it seems that the issue has to do with file time to download. If the file downloads in 30 seconds, the increment counts and sticks. If it takes that same file 2:28 (I simply kept trying until I had a slower download experience), then it does not increment. I have a larger file that I also use and it routinely takes 5 mins or so to download. It never increments. But the smaller file, if it downloads in its typical 30 seconds, it does increment on the initial click and sticks after page refresh.

I note that this user (comment #15) seems to have had this same experience and developed some work around: http://www.ubercart.org/forum/support/6671/file_download_limit_not_working

Is this a clue and can his solution either be implemented in the code or perhaps you can suggest some other workaround?

royerd’s picture

OK, here's what I did. I'm using the DEV version of Ubercart and the relevant file is uc_file.pages.inc

The result is that now when I click to download, it does not revert to the earlier counter increment on those files that take longer than 30 seconds.

 // Open the file and seek to starting byte
  $fp = fopen($file_user->full_path, 'rb');
  fseek($fp, $seek_start);

	//move up here from line 351 Dan Royer
    _uc_file_log_download($file_user, $ip);

  // Start buffered download
  while (!feof($fp)) {

    // Reset time limit for large files
    set_time_limit(0);

    // Push the data to the client.
    print(fread($fp, UC_FILE_BYTE_SIZE));
    flush();
    ob_flush();
  }

  // Finished serving the file, close the stream and log the download to the user table
  fclose($fp);
 // the original line moved above was here
 
}

I guess this means the count happens even if the file download gets interrupted.

TR’s picture

I tested this extensively in D6 last year, with very large files. I never had a problem with the counter. Are you quite sure your large file gets downloaded completely? The counter shouldn't decrement unless the download is complete, because in the case of a limited number of downloads available we have to make sure the customer gets the entire file.

royerd’s picture

I'd be happy to let you onto the account to see for yourself. We sell two files--one is larger than the other. The smaller typically downloads in about 30 seconds and it increments and stays as it should. The larger increments on the initial click but does not stick after completion and page refresh--until I moved the code like you see above--which I don't like doing of course.

Is it a complete download? Yes, it's an install file and I can download it then install it. We'd be getting a lot of complaints of incomplete downloads if it wasn't a complete download.

The pattern is that the counter would click up one on the initial click to download (as it should). After the download completes, the counter stays as it should until the page is refreshed (or leave the page and return) and then the counter is back to what it was before you started the download. This happens every time with this larger file. The smaller file it never happens on *unless* the file takes a bit longer to download.

Whatever I can do to help or demo this for you, I'd be glad to. Just let me know.

Dan

longwave’s picture

I am guessing what happens here is the database connection times out during a long file download, so _uc_file_log_download() fails. Do you get "MySQL server has gone away" messages in your log when this occurs?

royerd’s picture

Yes, actually I do get about 10 rows of server log, all related to mysql server going away error.

What does this mean? Does this mean there is some problem in my configuration? Or does it mean there is something to fix in the module?

However, this is not preventing a complete download. Does that make sense according to your understanding of that error?

Thanks for pointing to that lead.

Dan

longwave’s picture

We should fix it in code if possible, though there will be a MySQL configuration setting you can change that will help; I'm just not sure what it is.

#621148: "MySQL has gone away" error. Long running recursive rm of Boost flush cache causing MySQL connection to time out. is a similar problem with an interesting solution that we could borrow.

royerd’s picture

Hmm. The ping trick? I wonder how I could set the connection time higher or something?

royerd’s picture

Thanks for your thoughts on this. I'm not sure if somebody wants to fix the module--or whether this is a legit bug or a user setup problem.

But the out-of-the-box mysql set up has, I think, a 30 second wait_timeout. Mine did.

I used this module:

http://drupal.org/project/drupal_tweaks

to change that wait_time out to 6000 seconds--the longest time needed for my larger file download (most can download in about 4-5 mins). This solved the problem. Now the increment sticks after the download complete because the MYSQL has not "gone away."

Thanks for the help. I hope this db "tweak" doesn't have any unwanted consequences.

Dan

longwave’s picture

Title: file downloads counter not counting » Large file downloads may not be counted due to database timeout

This should still be fixed in the module if possible, as this is unexpected behaviour, and we shouldn't force people to change their database setup to accommodate this.

royerd’s picture

Thanks for your comments that led to understanding the problem. I'll leave my db tweak until it gets fixed and then perhaps set my time out back to 30 seconds or a minute. There is probably some reason the default is 30 seconds.

royerd’s picture

Ugh, unfortunately the database tweaks that allows me to set a higher wait timeout is interfering with my secure pages now. I guess I'll have to wait for this bug fix before i can use the file downloads.

turns out the wait_time setting is in etc/my.cnf file. I raised that limit and all is working again.

Dan

royerd’s picture

Guess I'm back to the hack until someone can create a fix for this issue. Turns out that moving the line as in comment #2 may be the only way to record downloads for now. Thought wait time out was the issue, but maybe not.

royerd’s picture

I don't know if it would help to have the log, but I can show that if needed.

StaceyF’s picture

Issue summary: View changes

I can confirm the solution in #2 works in Drupal 7 as well. I was having the same issue with audio file downloads. It would seem the wait time out is an issue because some audio files that were smaller for me would download and the limit stick on refresh and others that were larger would take longer and have the limit update initial but on refresh went back to 0. It would be great to have a fix or at least the option to turn this kind of fix "on" rather than having to hack the module since it's against good drupal practice.

TR’s picture

Version: 6.x-2.x-dev » 8.x-4.x-dev