Skip to content

Configuration methods in PHP to enable large uploads on a per-site basis

As dry as the subject of PHP configuration is, I thought a blog entry was necessary as I’ve just spent a fair bit of time digging around to find a way to configure PHP directives on a per-site basis. The mechanisms available vary based on the runtime environment and the method PHP runs.

My problem was to set PHP directives on a per site basis in order to enable large file uploads on a single web application running on the web server. I also wanted to modify the temporary upload folder PHP uses for file uploads, and enable file upload progress monitoring through the APC extension (preferrably only on the file uploader web app). The directives corresponding to these are in a number of different “modes”, so I was looking for a way that provided complete freedom over specifying the directives.

Depending on your PHP install and operating system there are several ways to customise your site’s PHP configuration. PHP itself can run in CGI mode, or as an Apache module. I’ll leave it to http://docs.joomla.org/Should_PHP_run_as_a_CGI_script_or_as_an_Apache_module%3F#What_is_the_difference_between_CGI_and_apache_Module_Mode.3F as it does a great job at explaining security and performance differences between PHP running in CGI or Apache module mode.

Determining your PHP runtime environment.

To determine the best way for configuring PHP on a per-site basis you’ll need to determine your PHP runtime environment (i.e. your operating system and whether PHP runs as a CGI or an Apache module). So, create a script that outputs your PHP runtime environment information:

  1. <?php
  2.  
  3.  
  4. ?>

You should then look at the “Server API” field, which will say something like “CGI/FastCGI” for PHP running as a CGI:

or “Apache Handler” for PHP running as an Apache module:

Now we’ve identified the mode of operation, I’ll explain some general methods for customising PHP directives on a per-site basis:

General per-site configuration methods

This should work on PHP running in any environment (Linux/Windows/Mac/etc) as either an Apache module or CGI.

Use ini_set() (limited number of options available)

You can customise a limited number of PHP directives on a per-script basis, by adding ini_set() to the top of your scripts. You can adjust PHP_INI_USER directives within scripts. See http://uk.php.net/ini_set for more information on this.

Allow user defined INI files (greater number of options available)

Edit your php.ini to permit user defined .ini files, by looking for a field user_ini.filename (which might be currently commented out). Uncomment it and state the filename you want to use for the user defined .ini files (which by default is .user.ini).

Then, within your web application (e.g. C:\phpwebs\helloworld), create a new file called .user.ini and add in the directives to suit:

upload_max_filesize = 1024M
post_max_size = 1500M

You can adjust PHP_INI_PERDIR and PHP_INI_USER directives in user defined INI files, which may or may not be enough. In my case, it was not, as I wanted to also update upload_tmp_dir, a PHP_INI_SYSTEM directive.

Define folder and directives in php.ini (most, if not all options available)

In this approach, you edit php.ini wherever it is located (see output from phpinfo() above), and at the end add your site-specific configuration, by specifying the folder that the web application resides in. Lets say our web app is located in C:\phpwebs\helloworld\. To configure the PHP runtime on this web app, add

[PATH=C:/phpwebs/helloworld/]
upload_max_filesize = 1024M
post_max_size = 1500M

At the end of php.ini.

Note virtually any directive can be customised on a per-site basis using this method, and this was the approach I went for when hosting a PHP web app on IIS to in order to adjust upload_tmp_dir for the uploader app. What I didn’t seem to be able to do was to enable some extension based directives on a per site basis. The progress meter failed when apc.rfc1867=on was specified under the per-site declaration, so I made this part of the global php.ini.

Per-site configuration options with PHP as a CGI in Windows IIS

Any of the general per-site configuration options mentioned above should work. You can also edit the registry to manage a subset of PHP directives, illustrated at http://www.php.net/manual/en/configuration.changes.php, in the section entitled ‘Changing PHP configuration via the Windows registry’. The process is as follows:

  • Open up regedit
  • Navigate to HKLM\SOFTWARE\PHP\Per Directory Values
  • Create keys corresponding to the directory hierarchy of your web app and at the child node specify the customised directives via New > String Value. Using our C:\phpwebs\helloworld\ example see the screenshot below for how you modify PHP directives:

Note that you can customise only PHP_INI_USER directives in this manner.

Per-site configuration options with PHP as an Apache module

All-in-one *AMP stacks (such as XAMPP) mostly have PHP running as an Apache module. Any of the general per-site configuration options mentioned above should also work for PHP configured as an Apache module.

If your PHP install in running this way, you can also edit httpd.conf file to specify PHP directives for virtual hosts and additionally directories and subdirectories exposed by the virtual host.

To do this:

1. Ensure AllowOverride All in httpd.conf. This should reside in the conf folder in the Apache folder.

2. In XAMPP, virtual host declarations are containerised and are specified in <apache_dir>/conf/extra/http-vhosts.conf. In this file you would type the following:

DocumentRoot "C:/phpwebs/helloworld"
ServerName www.helloworld.com
php_admin_value upload_tmp_dir "C:\tmp"
php_value post_max_size 1500M
php_value upload_max_filesize 1024M
php_admin_value apc.rfc1867 on

With this method you have complete freedom over which PHP directives you want to set. Valid apache directive syntax can be found at http://www.php.net/manual/en/configuration.changes.php.

Tagged , , , , ,

What does Word 2010 offer for reference management?

I’ve been having a bit of a play with Word 2010 since its release on MSDN to see if any improvements have been made in the area of reference management. Unfortunately it seems not a great deal has changed. So, instead, here’s a feature wish-list and how you can get by currently on some of the points by using Word (both Word 2007 and Word 2010) and some third party tools for all your referencing and citation needs:

  1. Support for citing as parenthesised and non-parenthesized references like in LaTeX. Unfortunately Word only supports the former, which is fine when citing references numerically, but it does not provide the flexibility which is important for Harvard author, date referencing. There is no automatic workaround that I am aware of to assist in this.
  2. Search and import citations into the Source Manager via common Internet repositories such as ieeexplore, citeseer, Google Scholar etc, or provide a mechanism by which this functionality can be plugged in. I’m currently using JabRef as my reference manager which provides a search of these libraries.
  3. A larger selection of bibliographic styles provided out of the box. In the meantime, BibWord, available on Codeplex, has a number of alternative bibliographic styles, including variations of Harvard style referencing.
  4. Make it easier to cite multiple authors within the text. Currently, the process is a little clunky.
  5. Import other bibliographic formats natively. I use JabRef as a middleman to store citations as it is able to deal with citations in a number of formats (Endnote, .ris, .bib etc). I then export the JabRef library into a Word 2007 XML bibliography. See my article on how to export a bib using Jabref into XML format in order to read it into Office 2007/2010.
  6. Offer a search when inserting citations so if an author/author tag or some other information about the reference  is known, you can filter the list without having to scroll through a (potentially long) list of citations.
  7. Sort the performance issues when rendering extremely large reference lists. To mitigate any performance issues you can export just the citations you need to Office XML format (see 5.) from within Jabref, rather than your entire library.
Tagged , ,

Enabling Alternative PHP Cache (APC) extension in Zend Server CE

I spent a little bit of time yesterday trying to code up a file progress bar for a project requiring large uploads. It seems the best (and the only?) way to do this in PHP is to use an extension called the Alternative PHP Cache, which amongst other things enables file upload status support and specfically enable a switch corresponding to RFC1867 support. I’m going to show you how I did this using the Zend Server CE PHP stack on a Windows Server 2003 x86 install.

I originally thought that APC was statically compiled into Zend as it pops up in the list of extensions in the Zend dashboard:

But, on closer inspection of phpinfo(), there was no reference to any apc directives at all.

So here is how I did it:

Enabling Alternative PHP Cache (APC) extension in Zend Server CE

  1. Download non-thread safe VC9 APC DLL (I went for php_apc-5.3-nts-svn20100226-vc9-x86.zip) from http://downloads.php.net/pierre/
  2. Unzip it and put the extension dll php_apc.dll into C:\Program Files\Zend\ZendServer\lib\phpext (assuming you left the Zend Server install location as its default)
  3. Add the following to your php.ini (in C:\Program Files\Zend\ZendServer\etc):
    ;Enable APC
    extension=php_apc.dll
    ;Enable upload progress bar
    apc.rfc1867=on
  4. Give Apache/PHP a restart

Now check out phpinfo() on the Zend dashboard and you should see something like the following, with apc and the various directives being output in the configuration part of the output.

Any of the APC file upload progress bar plugins (e.g. http://www.ibm.com/developerworks/library/os-php-v525/index.html) should now work.

Tagged , , ,

Getting the best out of an Acer Revo in Windows 7

A couple of weeks ago I picked up an Acer Revo on the cheap as a replacement for my old behemoth of a HTPC. The Revo is a “nettop” with netbook parts in a slimline case not much bigger than many routers currently on the market.

I picked up the basic version with 1GB RAM, and a single core Atom N230 running at 1.6Ghz running Acer’s custom Linux install. The kicker was the inclusion of the Nvidia Ion chipset which includes a Geforce 9400 on-board, sufficient for accelerating pretty much any HD content you want to throw at it. In use its practically silent, using a 2.5″ laptop hard disk and small active fan which throttles down during use.

First thing I did was to get Windows 7 on there to see how it would handle and I was pretty impressed with the experience. I left the Aero theme enabled as it seemed to perform better than running the Basic theme. Standby and hibernate works much better and quicker than my old HTPC. To get the best out of it for my HTPC related tasks I did the following:

  1. Downloaded and installed the latest Ion chipset, graphics and HDMI audio drivers from Nvidia. Select Download Drivers, then ION as the Product Type and ION (Desktops) as the Product Series.
  2. Downloaded Flash 10.1 beta (both active-x and the plugin for Windows). Update: the release candidate (Flash Player 10.1 Release Candidate 2) is now available on the previous link. After installation, you should see an immediate improvement when playing Flash video content on the web as it supports hardware acceleration making Youtube HD (720p and 1080p) and BBC iPlayer HD content fly. Note it doesn’t enable acceleration for downloaded content through the iPlayer Desktop application as this uses the Adobe Air runtime instead to play back video and this does not yet support GPU acceleration but I’m hoping it isn’t be that far off.
  3. Downloaded the latest version of Media Player Classic Home Cinema (currently at v1.3.1249) which hardware accelerates most of the HD content I’ve got out of the box without any additional configuration. If it’s doing the same with yours you should see ‘DXVA’ toward the bottom of the window when playing back your content.

If you have a 5.1 amp which supports DTS and Dolby Digital and want to get your content pumping out multi-channel audio in MPC-HC (should the content provide either a DTS or Dolby Digital stream) then you’ll need to do a small amount of configuration:

  1. Open MPC-HC and click View > Options
  2. Select ‘Internal Filters’ to bring up a list of source and transform filters
  3. Double click AC3 in the list of transform filters
  4. In the window that appears, set AC3 decoder and DTS decoder settings as follows:

Additionally, if you want a complete front end without navigating the Windows desktop, Boxee might be worth a look into as it also supports GPU acceleration both on the interface and during video playback. It’s also available for Ubuntu and supports the Ion chipset out of the box for accelerated video, for a free alternative. This is based on the very popular Xbox Media Center (XBMC) which also supports VDPAU (Linux’s implementation of DXVA).

Got any other tips? Feel free to share them in the comments :)

Tagged , , ,

And we’re back….

Apologies for those of you trying to access my blog over the past couple of days: normal service has now resumed after getting severely let down by my old web host. Luckily I had some recent (but not fully up to date) backups so all bar a couple of the posts are intact. I’ll recreate the others from my friend, the Google cache, ASAP.

If you spot any problems please do let me know and I’ll get it rectified ASAP.

Including Visio diagrams in LyX documents

If you want to be able to include Visio drawings within your LyX documents, the process is relatively painless as you can export the drawing as a PDF and embed the PDF directly into the document.

First, create your diagram in Visio as normal. Then, click File > Page Setup, select the Page Size tab and click the radio button entitled ‘Size to fit drawing contents’:

visio-size-to-fit-drawing-contents

The bounding box will shrink to fit your drawing, which makes for easier positioning within LyX as you won’t have any whitespace issues arising from borders from your drawing.

If you are using Visio 2007, and have the Save as PDF or XPS plugin installed, you may go directly to File > Publish as PDF or XPS and save the diagram as a PDF. If you are using Visio 2003, or 2007 but do not have the plugin, then you can install a PDF printer, such as CutePDF (just go for whatever you’re most comfortable with) and File > Print directly to the PDF printer.

Within LyX, the process of embedding this PDF into your document is really easy. Click Insert > Graphics, browse for the PDF file and optionally set the scale or width and height to suit. LyX will render a preview of the image within the document and when you compile it to a DVI/PDF, you should see the Visio drawing output inline with the text.

Tagged , , ,

Commenting on PDFs generated from LaTeX documents

PDF’s generated with pdflatex, the pdf generator for LaTeX documents which is used by default in LyX, cannot be commented on directly through the use of Adobe Reader alone (currently as of version 9). See http://www.tug.org/pipermail/pdftex/2008-August/007802.html for a good explanation for this. To enable this feature using only Adobe products you need to run the generated PDF through Acrobat Professional (which costs) and specifically enable commenting. This makes reviewing documents electronically impossible by using just the free tools that Adobe provide.

Luckily there are some great alternatives. I’ve used Foxit Reader and PDF-XChange Viewer in the past and both allow you to comment directly onto PDFs, whether or not the document has commenting permissions enabled in the first place. Any comments you add are portable and can be viewed in Adobe Reader as a bonus.

Tagged , ,

Update on setting up Ubuntu in order to build kernel modules

As an update to my “hello world” kernel module article, there is a much easier way to set up your Debian-based Linux (including Ubuntu) to build kernel modules, without manually getting the relevant kernel headers using apt-get.

I’ve tested this process with Ubuntu 8.04, 9.04 and 9.10 and it works great. Do the following to set up your Debian-based Linux environment for building kernel modules.

  1. sudo su
  2. apt-get install module-assistant
  3. m-a prepare

m-a (module assistant), will set up the appropriate build environment for you (including correct linux-headers and build-essential)
You can now skip to code part of the original article :)

Reference: http://wiki.debian.org/ModuleAssistant

Tagged , ,

Adding custom class files (.cls) to Lyx in Windows Vista / Windows 7 environment

When writing for publication, you may be offered a .cls file from the journal in question in which to format a TeX document to their specification. Whilst this works great in TeX, usually by copying the class.cls file in your working directory where all your .tex files reside and adding \documentclass{class} in the preamble (before \begin{document}), using these custom classes isn’t so straightforward in Lyx, so I’ll describe the steps required. I’m using the eethesis.cls class file as an example, which you can obtain from http://www.latex-site.info/. This class file aids in the presentation of a thesis or progress report which meets the requirements of formatting at the University Of Birmingham, UK.

There are a couple of posts I ran across which deal with this specific issue, here and here. None were specific to Windows Vista/Windows 7, so I’ll deal with that here. This assumes version 2.8 of Miktex and version 1.6 of Lyx. If you are using an earlier or later versions, replace with the correct version numbers where I’ve used them.

  1. Get a copy of the class file, and copy it into a folder with the same name into C:\Users\\AppData\Roaming\MiKTeX\2.8\tex\latex. So, for eethesis.cls, you should have a folder called eethesis within C:\Users\\AppData\Roaming\MiKTeX\2.8\tex\latex. This is Windows Vista / Windows 7 specific, you will soon see why…
  2. Create a new file and paste the following into it:
    #% Do not delete the line below; configure depends on this
    # \DeclareLaTeXClass[xxx]{article (xxx)}
    # Input general definitions
    Input stdclass.inc

    replacing xxx with the class name (without the .cls extension). In my case, xxx is eethesis, and the code above becomes:

    #% Do not delete the line below; configure depends on this
    # \DeclareLaTeXClass[eethesis]{article (eethesis)}
    # Input general definitions
    Input stdclass.inc

    Thanks goes out to http://wastedmonkeys.com/2007/09/27/adding-a-new-class-in-lyx-windows for this.

  3. Save this file to C:\Program Files\LyX16\Resources\layouts, naming it eethesis.layout.
  4. In a command prompt (type cmd in start menu), type texhash. What you will now see it doing is iterating through several folders for new classes, one of which (C:\Users\AppData\Roaming\MiKTeX\2.8\) is where we copied the eethesis.cls class file into.
  5. Within Lyx, hit Tools > Reconfigure, then restart Lyx.
  6. Open a document and click Document > Settings. Click on ‘Document Class’, expand the drop down menu and you should see ‘article (xxx)’ is visible, and usable, (like below) within the drop down menu.

lyx-document-classes

Tagged , ,

Batching video transcodes with Handbrake (Windows)

I keep all my media in a central location on a network store but I want to be able to play it on my iphone when I’m away without network connectivity. Most of the content is avi/divx/xvid which the iphone does not play natively.

Handbrake is a really slick transcoder which converts a wide number of video formats to those compatible with mobile devices. It offers a number of built-in profiles for many mobile devices, including the iphone, and comes as UI or command line interface.

Here’s a quick and dirty batch script for Windows which processes a given folder (this assumes you installed Handbrake into the default directory):

  1. FOR /F "tokens=*" %%G IN (DIR /B /S *.avi’) DO "C:\Program Files\Handbrake\HandBrakeCLI" -i "%%G" -o "%%G".mp4 —-preset="iPhone & iPod Touch"

Copy this into a .bat file in the root of the media folder you wish to transcode the media from. This script will iterate through all the .avi files in the folder, calling Handbrake, and creating an .mp4, suitable for playback on the iphone/ipod touch.

You can customise the batcher to suit, replacing *.avi in the DIR part of the batch file (which provides the input to drive Handbrake) with the type of media file you want to deal with, or replacing the --preset argument with any of those mentioned in the Handbrake wiki (there are profiles for most common devices, including Xbox 360, PSP, PS3, AppleTV etc). Great thing is, I can run the script and leave the PC whirring away overnight

Tagged , ,