Recently for Saturn SPL, as part of a prototype discussion, I was considering a fam based trigger for a process queue. We were already familiar with queueing processes in a mysql table, with auto_increment primary key, this should not be a problem. But when the number of processes increase, the table size too increases and finally we will be forced to remove those already processed. Also more than this, we wanted the table to me as compact as possible, meanwhile should be as accurate as possible. MySQL could not (AFAIK) stamp rows with mico seconds.
Continue reading “MySQL UDF – the first taste”
Author: Jiju Thomas Mathew
Invoke shell from MySQL trigger
No I am not insane, and after a long days search over the wide Internet, even google admitted defeat, there seemed to be no way to do this. Finally I had already dropped the idea or even let off the thing altogether. But recently for another project I needed to check in for an entirely different requirement and stumbled on the fact. And yes I checked it, voila the shell invoke from mysql trigger is possible.
Continue reading “Invoke shell from MySQL trigger”
String encryption with password
While searching for some thing, I found a string encryption code sample for Visual Basic, and I just wanted the same in php, and did a port. Just like what F. Balena has done over there, this function is also used for both, encrypt as well as decrypt.
<?php
function stringEncrypt($str, $pass){
$strlen = strlen($str);
$passIndex = 0;
$passLen = strlen($pass);
// null passwords wont encode
if(strlen($pass) == 0)
return $str;
for ($i = 0; $i < $strlen; $i++){
// get the next char in the password
$passChr = ord($pass[($i % $passLen)]);
// encrypt one character in the string
$str[$i] = chr(ord($str[$i]) ^ $passChr);
// modify the character in the password (avoid overflow)
$pass[($i % $passLen)] = chr(($passChr + 17) & 255);
}
return $str;
}
PHP SDK for Windows Azure
Microsoft is embracing the open world, by providing a wrapper or api to interact with their Azure Cloud services platform.
function getIpBehindProxy
We were worried, about all the comments on kerala online, being marked as spam by the akismet plugin. When on detailed examination, we found that the basic problem was that wordpress was logging only the immediate downsteam ip as the remote address, well ours was a bit confusing setup, but to handle the traffic we needed it that way.
A search for wordpress behind reverse proxy, landed me to the wordpress support page. In fact the 5th entry on that page is done by Gopka, who is the lead on this project from Saturn.
We started to correct the remote address by overriding the global variable making slight changes to the wp-config, such that we will not accidentally overwrite the changes while upgrading wordpress. Well the code
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $list[0];
}
when added to the wp-config, it started to log the first IP, and that would be mostly private IPs if the request was from organisations where internet was shared through proxies or using NAT. The case was same at our office, so we had to find the first public ip from the list of IPs and the code for function getIpBehindProxy was the out come.
Continue reading “function getIpBehindProxy”
WordPress object caching in file system
During the past couple of months, since we are maintaining a heavily loaded wordpress implementation, Kerala News Portal for Asianet, distributed across two servers, and having a daily visit of 50K, I was on the hunt for better caching and optimizing techniques. On the move, I happened to read the article by Jeff Starr, written some 15 months ago, and all the associated comments. It was sad to see that the file based cache was removed from wordpress, due to several reasons though.
After reading through this, I saw the official Function Reference for WP Cache, and the eAccelerator for WordPress by NeoSmart Technologies. Reading through the code written by Computer Guru of NeoSmart Technologies, tickled me and I just modified some parts, by pulling out the eaccelerator specific functions, and switching to a file system based store. I am not adding the code as pretty php code. Drop the file into wp-content, create a cache folder in wp-content and chmod folder to 755.
Download
Recently only I found that this has been outdated with new version of wordpress demanding more of the wrapper functions and capabilities. And this has been brought into the system. Functionally more or less the same, but will work on shared hosting for just object caching.
Download
Web Spider using php cli
Purely on academic basis, I had once helped to cook up a web spider, which is used to build site maps. The spider was written in php and uses a couple of reg-exp matches, and finally writes the full sitemap from the start url. The system is assembled using two classes, WebPage and WebSpider. Then to make it similar to linux utilities in the command line environment, some functions were scooped in.
Continue reading “Web Spider using php cli”
PHP Opcode Caches, switching between
Opcode Cache
A PHP accelerator is an extension designed to boost the performance of software applications written using the PHP programming language. Most PHP accelerators work by caching the compiled bytecode of PHP scripts to avoid the overhead of parsing and compiling source code on each request (some or all of which may never even be executed). For best performance, caching is to shared memory with direct execution from the shared memory and the minimum of memory copying at runtime. A PHP accelerator typically reduces server load and increases the speed of PHP code anywhere from 2-10 times, depending on factors such as the inherent execution time of the PHP application and the percentage of source code actually executed on a given request. While a code optimizer may even slow down overall performance when used in isolation, it can provide an additional performance boost when coupled with a code cache as the optimization effort is performed just once.
Continue reading “PHP Opcode Caches, switching between”
JavaScript Aggregate; WordPress plugin
Collects all different linked javascripts and replaces with a combined single script, optionally compressed. Based on code originally written by David Holmes, Martin Kliehm, Gaetano Giunta. Uses the PHP adaptation of JSMin, published by Douglas Crockford as jsmin.c, also based on its Java translation by John Reilly.
After reading about Website Performance Tweaks, and a lot of other blogs and slides, I thought about how to cook up a javascript aggregate plugin for wordpress. The out come is wp-jsmin. Though this is in its infancy, it is being used in this blog, to combine all linked javascript to a single link, thereby reducing server requests. This code is still in the testing stage, and may break if the used scripts do not pass lint checks. I am planning to shift all the options to a options page in the wordpress admin page.
Those who are daring enough could download and try. Please put a comment here if you are using this on your wordpress. And for others who would like professional help, I would be most pleased to extend my services through RentACoder. Or for a whole dedicated wordpress team to design, build and maintain sites like Kerala News, Cirrus Travles or Rajeev Gandhi Center for Biotechnology, send an inquiry to Saturn.
Distributed Media; a WordPress Challege
Though when the team at Saturn decided to build kerala online, on wordpress, they were quite confident, the complications started to get under their skins when the first wave hit the portal and at a point were the portal was being run from a single server and reached about 35K visits per day. The server was running on apache with about 2G Memory and hosted in Asianet the ISP division. There was times when the server was running at load averages above 60. All workarounds were getting futile, and there was certain times, like evening and early morning when the server hits the upper limit and ceases to respond. Continue reading “Distributed Media; a WordPress Challege”