Archive

Archive for the ‘Code Snippets’ Category

php memcache simulate using file system

September 13th, 2011 No comments

Recently we were facing some difficulties, where we had facilitate implementing a copy of an application on a development environment with our client. The most difficult part was that though we could coax php to load libraries, we could not install any system services. We were supposed to install only a web application to a pre-configured virtual host. Since we had enjoyed the facility of having Memcache at our own development environment, some core part of the application which was required only when users are logged in, was using the Memcache. Also our database abstraction layer was heavily depending on the memcache library. We immediately identified that the requirements were not met and specified that the environment was not as we required. But the support people were so adamant that they insisted us to proceed by commenting out all references to the class. Well I can also be tough.
Read more…

Categories: Code Snippets, PHP Tags:

url shortening script using MariaFramework

September 10th, 2011 No comments

Just as a proof of concept, we had tried to port or even rework the whole of asianetindia.com using MariaFramework. The task of migrating the wordpress admin side, being herculian, this was delayed in pushing to production and it is still in poc stage. Now to nail down the fact that MariaFramework is production ready, we need to show off some generic applications. Here comes one, though the commenting in the main application is poor, I hope one can implement this and get running with out much headache.

Download the full script url shortening script using MariaFramework (1496)

Submit all your comments and views as posts to MariaFramework

Compressing php source files for embedded applications

September 6th, 2011 Comments off

Compressing php code is not been a tough task, and this is not for the purpose of obfuscating or encoding to make closed source distribution. But to create compact files which can be distributed by pasting into inline text, or into email without the need for attaching. The size will be drastically reduced. Actually at Saturn we did this to help us achieve to load a whole application on to a very space constrained flash disk. We were the least bothered about the process cycles taken to evaluate the php files since they will happen only once in a blue moon when the embedded system restarts. I am pretty sure that for closing source, there are other solutions.
Read more…

Categories: Code Snippets, PHP Tags:

php smtp email direct to mail box delivery

January 5th, 2011 No comments

For sending status mails, with varying from addresses, for several of our projects at Saturn, we were using the phpmailer which uses our smtp server with authentication. Well our smtp host had a limitation of 250 emails per day. When our requirements grew out of this limit, mails started to pile up. Sure I could install exim4 or sendmail on my boxes, and that is what I did for immediate resolution. But here comes a new requirement, that the mails sent should be marked as such, and those which failed should be marked with the exact response of the receiving end mailserver.

At this point I thought about an SMTP direct to mail box Delivery system. My favorite language being PHP, and primary library being Google, I tried all possible ways, according to me, and they were not the right ones as I came to know later. All these did not get me in the right direction. And finally thought about writing one. Here too, being lazy, wanted to have the code from some ones work to ignite me. Okay I found the phpbb’s smtp.php referred on the net, and the function smtpmail from the same was the right choice.
Read more…

A Mathematical Captcha – Reinventing the Wheel

April 19th, 2010 2 comments

For a long time I have been using the image captcha with random characters, and got fed up. I had seen numeric computational captcha or Mathematical captcha where one has to calculate the answer of an equation with simple arithmetic and supply the result for verification. Last night I was pondering over this while watching a movie on the TV. Well the out come is obvious.
Read more…

Categories: Code Snippets, PHP, Tips Tags: ,

Function to format bytes in human readable format

April 8th, 2010 No comments

I was digging through my old codes to get this, still could not find. Hence when I wrote it, just made a note here such that later it wont be difficult to find atleast for me.
Read more…

Categories: Code Snippets, PHP, Tips Tags: ,

Formatted XML, the php dom way – Best for debugging

April 3rd, 2010 No comments

Recently in a discussion on linkedin PHP webservice – Logging Requests/Responses, Roy de Kleijn had asked “how can I print the XML in XML structure, in stead of a single line of text”, which triggered me a thought. This may be trivial for veterans, and still a new information for newbies.

Read more…

Categories: Code Snippets Tags: ,

Posting to wordpress using php cli and xmlrpc

February 8th, 2010 9 comments

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.
Read more…

Categories: Code Snippets, PHP, Tips Tags: , ,

php MsSQL Backup

January 30th, 2010 7 comments

A php script to dump database as sql from MS SQL

We started porting (provide dual support) one of our application from MySQL to MSSQL, sorry, actually we were trying to run the same code base on either MSSQL or MySQL as the client wishes. And those who knows both, will agree to the level of toughness and agony when considers the fact that all of us are on MySQL and are new to MSSQL. In this context, we wanted to provide backup and restore to the application administrator through the system itself, and was not contented with the .bak files provided by MSSQL backup.
Read more…

Migration from MySQL to MSSQL our solutions – Continued

December 14th, 2009 1 comment

In the previous post, I had specified that a code analysis would be presented later on, which is happening now. Though I am not permitted to abstract the whole database abstraction, which would otherwise divulge the core business logic of the system too, I do expect that the following would be enough to guide a MySQL PHP developer to port his application to MSSQL 2005. Mostly the compatablities are maintained. But for the database design, we had to let away some of the wonderful features from MySQL.

We started by a code auditing and reworked the system such that we did not use any group_concat through out the system. Also all timestamp and datetime fields were changed to varchar(19) since we were already feeding those fields with the php function date’s return value or ‘now()’. But there was quite a handful of areas where we were using STR_TO_DATE and with different formats. So this had to be handled in its own way. And it is here we started our regular expression war path.
Read more…