Doing this, we have had the occasion to work with Drupal, to appreciate it and its community, and to use a large number of existing community-contributed modules. Also, we've gained experience in writing several new modules, to answer our needs and those of our websites.
Some of our needs are not specific to the websites we're working on, and we believe that sharing a couple of modules we developped could be interesting for both the community, and us.
The first module we would like to share as open source is related to the gathering of statistics. More precisely, it allows one to keep track of how many times the detail page of each node has been opened.
Drupal's statistics module only collects data when the HTML ouput for a node is generated. It does not suit our needs, as our web-servers are behind a reverse-proxy that is used as cache for an important portion of our page views -- which means the PHP code is often not executed, and the statistics would not be gathered.
To deal with this situation, we have created a new module, that we've called bg_stats. In a few words :
* It adds an img tag to the HTML code of the nodes pages.
* This img tag is used to load a PHP page on our server, passing it some data to indicate from which node it's called.
* That PHP script (independent from Drupal, in order to be as lightweight as possible) logs accesses to a file (and not a database, for the same reason).
* And, finally, there's a cronjob that aggregates data from this file, and uses them to populate the statistics tables.
It means statistics cannot be seen immediatly... But it also means statistics will work in a setup where the PHP servers are behind a reverse-proxy that acts as a caching layer.
Obtaining a CVS account is the first step in the process of sharing and open-sourcing a module... So, here we are !
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | bg_stats.zip | 5.4 KB | G.H.M. |
| #1 | bg_stats.zip | 5.27 KB | G.H.M. |
Comments
Comment #1
G.H.M. commentedAdding zip containing our "bg_stats" module.
Comment #2
avpadernoComment #3
avpadernoHello, and thanks for applying for a CVS account. I am adding the review tags, and some volunteers will review the code, pointing out what it needs to be changed.
There is a Drupal function to use in such cases.
It usually not a good idea to unconditionally include code contained in PHP files. If the files contain form handlers, theme functions, or menu callbacks, Drupal core code allows to third-party modules to define which files must be loaded in the implementations of
hook_menu(), andhook_theme(); in these cases, Drupal loads the file only when necessary.Hook implementation comments should be like the following one:
The first argument of
drupal_add_js()is JavaScript code, without any<script>tag.The function to use is
drupal_set_header().Comment #4
G.H.M. commentedHello,
Thanks for the review!
I'm attaching a new version of the module, in which I've tried to fix as much as possible :-)
=> I'm switching the status of this issue back to "Needs review"
For a bit more informations:
1. fixed
2. fixed (using module_load_include, and not require)
3. fixed -- and checked if the same mistake was made elsewhere; doesn't seem so.
4. fixed : now using hook_footer() to add the HTML code at the end of the page, instead of some dirty hack based on drupal_add_js()
5. The function drupal_set_header() looks fine to me ; but, in the register_stats.php file, we are "outside" of Drupal : this is a simple non-drupal PHP script, to avoid the overhead of loading Drupal's core and everything.
So, we can't use any drupal_* function in there -- which is why we are using header().
(I've added a comment at the top of that file, to be more explicit about that fact ; and to prevent other developpers looking at our code from thinking that not using Drupal's functions is OK)
I have also talked about your comments to other developpers arround me -- should help us all, in the future ;-)
Comment #5
avpadernoThank you for your contribution!
I am going to update your account so you can opt into security advisory coverage now.
These are some recommended readings to help with excellent maintainership:
You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
I thank all the dedicated reviewers as well.
Comment #8
avpaderno