Sending files through Apache with mod_xsendfile

If you ever wanted to serve big or many files through PHP and needed to check permissions or do any other calculation upfront file delivery, you might want to think about an Apache module called mod_xsendfile. With it you’re able to separate permission checks and other script related stuff from the slow part of file delivery in which PHP is not best at.

And getting it up and running is pretty simple.

a2enmod xsendfile
apache2ctl restart

Now, in your virtual host configure your host to pick up the module and maybe define a folder wich the module is allowed to send files from.

#enable the module for your host
XSendFile On

#define a white list folder outside your DocumentRoot
XSendFilePath /some/path/outside/my/docroot

That’s it on the Apache side of things.
Now, simply tell Apache to handle the file transfer itself in your script. This is done by sending the X-Sendfile-Header. No more needs to be done. No file reading, nothing. The whole delivery is being delegated to Apache.

//some code to check permissions, get the file name, rescue the world or whatever
//...
header('X-Sendfile: '.$absolute_path_to_file);
header ('Content-Type: application/octet-stream');
header ('Content-Disposition: attachment; filename='.$some_file_name );
exit();

And that’s it. Now all your validation stuff will be done by PHP while file delivery is done by Apache.

Gedittools – a new version

First of all: Thanks to all folks using my Gedittools plug-in for Gedit! All the mails and comments and download stats show that I was not the only guy looking for missing functionality in Gedit. During the past week or so I found some time to improve the XML-highlighting mechanism for Gedittool:

In fact, I re-designed and implemented the algorithm to find and highlight XML-tags from scratch. It is now much faster in searching and highlighting.

All other features like

– counting search results
– highlighting marked words throughout the document
– integrating a meld-interface to compare / diff opened files

remain as they are. Feel free to download the plug-in at Github.

Gedittools - a plug-in for gedit

Citrix Client on Ubuntu 10, 64 Bit.

Unfortunately, there is no 64 Bit package for the Citrix client 11. So, it is a smaller challange to install the client using 32 bit libraries. There are a couple of nice tutorials on the net. The one which helped me most was the how to by I can has linux. Basically it describes, that one should download the current 32 Bit Linux client from the Citrix Download Page. After running the basic installation you’ll need to download the Motif 32Bit Libraries, extract its files using ar and copy its libs to /usr/lib32 on your Ubuntu system.

But I still had a few issues installing the client: A symbolic link called libXm.so.4 was missing in the first place. To fix that, I did the following:

cd /usr/lib32
sudo ln -s libXm.so.3.0.2 libXm.so.4

Now, I was able to start the client: /usr/lib/ICAClient/wfcmgr

Trouble connecting via SSL

But when I tried to connect to a SSL Host, the connection broke telling me that To fix this, 2 steps are required. Download the certification files. Now, move the files to /usr/lib/ICAClient/keystore/cacerts or whatever the installation directory of your client installation is.

After that, Citrix client and connecting SSL hosts worked like a charm.

Gedittools – a plug-in for gedit.

Update September 21: The XML Highlighting algorithm has been re-implemented. Therefore, this feature is now much faster than before. Also, it is not triggered automatically. There is a new button in the toolbar to start XML highlighting.

During the past few weeks I extended gedit by several little plug-ins that I needed to have for my daily developer work. Now, I merged all those to one single configurable plug-in called gedittools.

It comes along with the following features:

  • XML highlighting: After hitting the highlighting button in the tool bar, the complete tree inside the file will be highlighted. Depending on depth different colors will be used.
  • Selection highlighting: After a double click on any word, all occurrances of the selected word will be highlighted throughout the whole current document.
  • Search selection count: After a double click on any word, all occurrances of the selected word will be counted and the sum will be displayed in the status bar of the document.
  • Launch meld to compare files: A button is added to the toolbar of gedit to allow launching meld. Therefore a screen will be displayed: It allows selection of a file which will be compared to the current active file in gedit.

The plug-in is configurable: You can choose which plug-in you want to use. To make use of the meld launcher feature, an installation of meld is required. Refer to the README file for details.

Download here

If you want to use the plug-in, feel free to download it at github: http://github.com/mmuell23/mmuell23

To install from git:

git clone http://github.com/mmuell23/mmuell23.git
cp -r mmuell23/gedittools/* ~/.gnome2/gedit/plugins

Activate plug-in in gedit preferences and configure it as you wish.

Install from zip File:

You might also download the plug-in as a zip file from github. Hit the “download source” button on the top right of the site.

Extract all files and copy to ~/.gnome2/gedit/plugins

Activate plug-in in gedit preferences and configure it as you wish.

Plug-ins for gedit: count results or compare files.

Well, after I could count words in a gedit document based on a selection I made, I decided to add another missing feature:

I needed a diff tool to compare two files that are currently opened in gedit. Unfortunately, gedit doesn’t come along with these kind of features. So, another plug-in was needed.

Meldlauncher

What it does? It simply starts the open source diff & merge tool Meld using two documents opened in gedit. That’s why I called it meldlauncher. Therefore, if you want to use meldlauncher, you will need to have Meld installed. On Ubuntu do something like this:

sudo apt-get install meld

If there are only two documents opened in gedit, meldlauncher will launch Meld and pass those two files to it. If there are more than two documents opened, meldlauncher will open a selection dialog from which you can easily choose the document to compare the current document with.

I moved both the counter plug-in and the meldlauncher plug-in to Github. Feel free to grab it from there:

http://github.com/mmuell23/mmuell23