Archive

Archive for the ‘PHP’ Category

Number Base Converter, converts numbers from any base to decimal and vice-versa

December 27th, 2009 Yervand Aghababyan No comments

Keep in mind that if you just want to address some URL in a short way then you don’t really need to read this article. You just have to use one of the multitude of services which provide URL mapping to tiny, generated URLs. Some of those services are: http://tinyurl.com/, http://u.nu/, http://bit.ly/. Just use the one you find the sexiest ;)

What i needed was a way to make URLs on my website as short as possible. I had a huge list of numbered entries each of which had it’s own unique ID and a URL looking like this: mywebsite.com/entries/789465479916 .  The best way of making the last number part of the URL as short as possible i found is converting the huge decimal number to the base of 62. Why 62? Because we’ve got 62 alphanumerical symbols there (0-9a-zA-Z) !

The first thing i found after some googling is that php actually provides a function named base_convert() which does what i want. BUT! It doesn’t support base of 62 and really huge numbers. A little disappointed i left this function be and resumed my search of the ideal solution! :D

In the comments of base_convert() i found a wonderful comment doing nearly exactly what i want. The only bad thing about it was that it didn’t support bug numbers. So i modified the code to use the bcmath php extension which provides support of huge number calculations. Bellow is the modified code.

Read more…

Using PHP ssh2 lib to create simple SSH client with ANSI support

December 25th, 2009 CyberJoe 6 comments

If you’re a real geek, you might want to make an ssh client… using  php, well, this is something that no one will probably ever need to do… but if you’re reading this, maybe it happens so that you need it :)

So, to start with, there is a php extension called libssh2, and it’s really tricky to install it on some server configurations. I’m not going to discuss that part here because it’s purely server administration issue. I will just get to the coding part.

What we want to do here is to create php script that would run from console, will connect to remote ssh server, execute commands, and display output just like every ssh client does. The first problem is – libssh2 documentation on php site really sucks.

Read more…

Categories: IT, PHP Tags: , , , ,

ADODB-Session optimization on servers with high load

April 28th, 2009 Yervand Aghababyan No comments

We had an issue today on a server with a high load because of ADODB’s session mechanism using MySQL as session storage engine with MyISAM table engine as advised by the manual of ADODB-session. Our server’s load is: 2500 new session creation every minute with about 17000 concurrent user sessions. A separate dedicated server (Amazon 2.3Ghz dualcore Xeon) was for he sole purpose of storing session data but the machine was not catching up.

So what basically happens here is that the default MyISAM table blows up in a matter of 10-20 minutes because of the tremendous amount of inserts/updates done on the table. Read more…

Categories: IT, PHP Tags: , , , ,