Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-10-29 19:05:57

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

How are the download counts filtered?

Hi!

I have a file that shows about 700 non-error requests in my server logs, but only 120-some downloads according to Textpattern’s download count.

I see that Textpattern does not record hits for all file requests, as follows:

if ((connection_status() == 0) and !connection_aborted()) {
        safe_update('txp_file', "downloads = downloads + 1", "id = ".intval($pretext['id']));
}

…but I don’t understand how connection_status() and connection_aborted() work to filter the results.

I have never noticed such an extreme difference between my server logs and Textpattern’s numbers before, and I’m not sure how to explain it to the site owner. Can anyone explain in basic terms what the “connection status bitfield” is and why it is used to filter what gets logged as a download? Is there an easy way to identify such requests in the server logs?

I think I understand “connection_aborted()”, but I don’t know how to identify aborted requests in the server logs either.

Thanks in advance for any guidance you can provide!

Cheers!

Last edited by johnstephens (2019-10-29 19:30:53)

Offline

#2 2019-10-29 20:45:28

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: How are the download counts filtered?

One possible explanation: Are your non-error requests for …/files/filename.pdf or for …/file_download/123/filename.pdf?

Only downloads passing through file_download are counted by textpattern.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2019-11-04 12:50:42

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: How are the download counts filtered?

They were all file_download or File+download urls generated by Textpattern tags.

I think I identified the issue.

It’s an audio file, and my template uses a custom field to display an associated file as an HTML audio element. When someone clicks “play” on the audio element, the file immediately begins to buffer.

For smaller audio files, buffering the file for even a short time over a high speed connection results in a complete download; that is, a download that PHP doesn’t count as aborted.

But for larger files like this one, visitors who listen to only part of the file using the browser’s built-in audio player will only buffer part of the file more frequently. This results in more aborted downloads.

My server logs pick up all those requests, aborted or not. Textpattern only records downloads when the request is neither aborted nor timed out, per the code I posted above from textpattern/publish.php. If I’m right about the cause, there should be a bigger discrepancy between the logs and Textpattern download counts in proportion to the size of the file.

Offline

Board footer

Powered by FluxBB