jgiam.com

Just another WordPress weblog

Archive for the ‘php’ tag

Optimising LiteSpeed Web Server: 30 seconds to less than 1 second

without comments

I chose to use the LiteSpeed Web Server over Apache HTTP Server because of the low memory footprint, as well as better performance for PHP. The GUI admin interface is also a big plus point, making it easy to administer the server.

As I was adding sites and working to bring them online, I realised that my sites were loading very slowly. I installed WP Tuner, a WordPress plugin, to try and see if the bottleneck was on LiteSpeed or MySQL. From the statistics, the delay occurred at the very first “Start” marker, taking 30 seconds, or even as long as 60 seconds. This wasn’t a problem with MySQL then. Next, I used top to monitor CPU and memory usage. It turns out that each PHP process took up 20MB of memory. With a VPS of only 128MB memory, and each site load using multiple processes, this was a huge problem. I was quickly running out of memory, and there was a lot of swapping. A quick search on Google, and I found this page of documentation, which states:

There are two ways to let PHP handle multiple requests concurrently, Server Managed Mode and Self Managed Mode. In Server Managed Mode, LiteSpeed web server dynamically spawn/stop PHP processes, in this mode “Instances” should match “Max Connections” configuration for PHP external application. To start PHP in Self Managed Mode, “Instances” should be set to “1″, while “LSAPI_CHILDREN” environment variable should be set to match the value of “Max Connections” and >1. Web Server will start one PHP process, this process will start/stop children PHP processes dynamically based on on demand. If “LSAPI_CHILDREN” <=1, PHP will be started in server managed mode.
Self Managed Mode is preferred because all PHP processes can share one shared memory block for the opcode cache.

I configured LiteSpeed to use Self Managed Mode as described, and restarted the server. I then loaded my sites in my browser, and just like that, my websites loaded in under a second. Just to make sure it wasn’t due to caching, I browsed several pages of the sites, and everything worked perfectly. It certainly pays to spend a bit of time analysing performance, reading documentation and tuning the server. :)

Written by Jon G

October 29th, 2009 at 11:47 am

Posted in Techie Corner

Tagged with , ,

Using Zebra for batch processing

without comments

As mentioned in my previous post, Zebra, more specifically, zebraimg, the barcode recognition component, is fast and rather accurate. However, the program isn’t really made for batch processing of barcodes. Yes, you can execute zebraimg *.jpg, but the problem is that it is difficult to extract information on which barcodes were successfully recognised, which were ambiguous, and which failed. I initially ran this command to process my barcodes, but ended up having to cross-check the results, which wasted quite a bit of time. I wanted some formatting of results to make it easier to identify problematic barcodes.

A simple script would be able to format the recognition results. Because I am not familiar with shell scripting, I wrote one in PHP instead.

The gist of the script is that it scans the working directory for all JPEGs, runs zebraimg and writes the result to a file. The result is saved in a CSV format with the filename and zero or more recognised barcodes.

Read the rest of this entry »

Written by Jon G

January 13th, 2009 at 4:10 pm

Posted in Techie Corner

Tagged with

123a.org relaunched

with 2 comments

Some time back, I had to remove the old 123Avatar site because my webhost no longer allowed me to use PHP’s exec() or system() functions, which was required to use ImageMagick. Instead of rewriting the site to use the gd functions, I decided to relaunch 123a.org as an image hosting service.

The site is based on Mihalism Multi Host, but with several modifications. The first allows me to track image views (the original version linked directly to the image files). This allows me to collect stats on the views as well as to implement some bandwidth controls or anti-abuse blocking in future. The second is to make use of Apache’s URL rewriting to generate nice URLs. 

Yes, there are hundreds of free image hosts available now: Imageshack and Photobucket being the more popular ones. So there’s really no particular reason to use mine. But, hey, just give it a shot if you like. :)

123a.org – Fast, easy and free image hosting

Written by Jon G

August 15th, 2008 at 12:51 pm

Posted in Techie Corner

Tagged with ,

SimpleViewerAdmin Mods

without comments

I designed a website for a friend, who wanted to use SimpleViewer for his portfolio. I wanted a dynamic gallery, rather than a static one requiring him to use, for example, Picasa to manage the gallery and then upload it. Thus I searched and came upon SimpleViewerAdmin.

He requested a hidden album feature such that the album can only be accessed directly through its URL.

Read the rest of this entry »

Written by Jon G

December 29th, 2006 at 11:22 am

Posted in Techie Corner

Tagged with , , ,

Simple Syntax Highlight

without comments

I found out that using ‘<’ and ‘>’ within <pre> tags was illegal. So I started looking for a way to convert program code into HTML.

Later on, for my tutorial for my programming module, it involved putting code into a Microsoft Word file. Doing so was tedious. If I copied and pasted from my editor into Word, the text would be pasted as normal text, and Word would format it in, for example, Times New Roman. Plus, the syntax highlighting that was in the editor was gone.

So now, I wanted something that could syntax highlight my code as well.

I came across GeSHi – Generic Syntax Highlighter. It was exactly what I wanted.

I hacked up a simple interface so I could paste code and convert it easily, and so, created Simple Syntax Highlight. You can choose the language (I only added the more common ones), whether to display line numbers, use CSS, and display HTML source. This solved both my problems, since now I could paste my code in valid HTML in my webpages, and I could also paste my code into Word with a fixed-width font, and syntax highlighting.

I called this “Simple Syntax Highlight” because I intend to create a database-driven site in future, to store converted codes, maybe a comments-system as well. But that won’t be anytime soon, as I have my Uni work to cope with.

I welcome any feedback. If you spot a bug, do let me know as well.

Simple Syntax Highlight – http://jgiam.com/geshi/

Written by Jon G

February 7th, 2006 at 8:40 pm

Posted in Techie Corner

Tagged with