Migration from MySQL to MSSQL – Quick Tip

With the help of some colleagues, I could export all the indexes and primary keys, which we were using from a MySQL table as MSSQL compatiable TSQL using a union query and on the MySQL information_schema.

With the help of some colleagues, I could export all the indexes and primary keys, which we were using from a MySQL table as MSSQL compatiable TSQL using a union query and on the MySQL information_schema.

I did the migration to MSSQL using some tips found online, and calling a sp after connecting directly with the MySQL server. Actually forgot how it was done. Anyway it does not matter in this post. Will add it as a comment later on. The important matter was that, the method did not import any of the indexes, or primary keys. We manually created those were absolutely necessary to roll out the project. And now that we were about to release a service patch, and this includes more incredible search methods, the indexes are absolutely necessary.
Continue reading “Migration from MySQL to MSSQL – Quick Tip”

Quick and dirty htaccess rewrite for Lighttpd

Writing this post and am getting ready to hide behind strong walls, since mostly lighttpd is meant to fly light, or serve faster without the bloat and dynamic flexibilities. But certain situations may occur where one may have to forget the religion and behave sensibly. For a major project which was collaborated by different teams of our spread out offices, one part was developed by a team who were more exposed to benefitting the furls (friendly urls), by using apache rewrites. The bang off was detected only at the last moment of roll out to the beta deployment at client environment.
Continue reading “Quick and dirty htaccess rewrite for Lighttpd”

Posting to wordpress using php cli and xmlrpc

A reader once asked me if I could build a command line tool which takes title from one file, and content from another file to create wordpress post. I tried, which finally gave an outline to this script. I dont think that this is very high fly, but for those whom the xmlrpc is mumbo, this might be somthing worth looking into.
Continue reading “Posting to wordpress using php cli and xmlrpc”

Short PHP twitter-counter

While strolling around I found some bits and pieces which I put together to get a short twitter counter in php.

<?php
ob_start
();
 
$json file_get_contents("https://twitter.com/statuses/user_timeline/php_trivandrum.json?count=1");
$data json_decode($jsontrue);
ob_get_clean();
 
echo 
$data[0]['user']['followers_count']; 
?>

Nothing more to write now..

Importance of event logging in server side scripting

Now a days script driven web applications are getting more and more complicated with background operations and triggered events. Debugging or event tracking is tough once the application is moved into production. Fresh and aspiring programmers are always too cautious to wade into deeper waters, and always go with line by line testing. Almost always in the course of debugging or code optimizations I see a lot of them using file_put_contents or echo to check variables at a particular point of execution.

I always gave the pressure to use a good logging system from the start itself, and to add level based message logging with debug_backtrace wherever needed. The most recent class abstraction for php programmers which is being used in our custom framework is attached to the downloads here. The file logging is being done after serializing, compressing and base64_encoding to keep logs in single lines, and to make sure they dont take up too much of the space.
Continue reading “Importance of event logging in server side scripting”

function array_flatten

This is not much to brag about, still we had a very large dataset as variable dimensional and variable depth, which we wanted to be sent to a custom function using prototype.js. For the data exchange we use JSON, but the varying depth and related tags, made us to do like hell in the javascript templating that we had to find a method to flatten the array in such a way that each of the associative keys would not be mangled.

The final out come is function array_flatten


function array_flatten($p, $ki = ''){
    if($ki !== '') $ki .= '-';
    $rv = array();
    foreach($p as $k => $v){
        if(is_array($v))
            $rv = array_merge($rv, array_flatten($v, $ki.$k));
        else
            $rv[$ki . $k] = $v;
    }
    return $rv;
}

The flattened dataset, helped us to do rendering in less than half the iterations, and the application response was more better after using this.

function is_ipaddress

Well this may not be new to you all, but still, when I was on the lookout how I could validate an ip address, all the regular expression techniques either failed on valid addresses or bloated too much. The out come was wrote a piece of code which may help others if this is correct, in its way. Not sure, since most of the addresses which I tested against the other validation methods, and failed or non valid ones which passed were blocked here.
Still I am not the ultimate, if you have better suggestions than the code given here, please do so. Continue reading “function is_ipaddress”

FLV Streaming with PHP

For pseudostreaming I did see some of the projects and suggestions which used a serverside scripting language, to achieve the same as the plugins or modules for the web server software does. Ports in perl, php and python as well as shell was also found, but all were bloated, that they were not transparent. So I thought I would give a try.

Pseudostreaming is a protocol that can be installed on regular HTTP servers such as Apache, Tomcat, IIS or lighthttpd. It uses a server side script for Flash-to-server communication. The player sends a HTTP request to the server with a start time parameter in the request URL’s query string and the server script responds with the video stream so that its start position corresponds to the requested parameter. This start time parameter is usually named simply start. This same technique is used by the ultra-popular YouTube service which uses lighthttpd servers.
Continue reading “FLV Streaming with PHP”

sqlite3; I am falling in love..

After about a decade of php and mysql, with just deviating only in the scripting or language area, today morining, I felt like digging into the sqlite3, which a lot of people are referring to, and some good RIA players are paying attention to also. The big names that sqlite website brags about are Adobe, Symbian and Firefox.

Jumping straight into the hands on, though for a prologe or introduction I will brief the respective situation. Kyle Newton of Galaxy WD, a client of Saturn SPL wanted a website to have the famous USAPostalCodes db, but he wanted the system to use pre imported flatfiles, and with about a couple of hours, we could pre import the USAPostalCodes db to the recommended format, though the whole data size was now 170MB. The pages where being generated on the webserver under 1/100 th of a second. Along with php ob_gzhandler was giving a good output. The client was almost satisfied, though he had some other views and that was not about the technology.

Continue reading “sqlite3; I am falling in love..”