Some evening I was implementing behavorial patterns in my framework’s ORM and I desperately needed something like Ruby mixin or C# extension method or like trait/graft in PHP6+. So I was curious to see how can I implement mixins in PHP. If you don’t know what mixin is, I will tell you at once.
So, I invite you to follow me on paths to implementing mixins in PHP and programming a small library to support them. This article targets beginner and average level programmers. Just be sure you know what OOP is. During the process, I will also make some small mistake about nuances of PHP 5.3 work with classes, will point to it and suggest my solution to it. Good reading!
Continue reading “Practising OOP in PHP5: emulating mixins (Ruby-like)”
My search for a good PHP IDE never stops 😉 My choice was Zend Studio until recently. But Zend Studio is not free and it’s free analogue – PDT – lacks some features like refactoring (PDT is also mainly developed by Zend, so, I think, Zend will always keep it low to prevent competition with Zend Studio). Also, it is monstrous (More than 300Mb installer) and it definitely lacks good Symfony support.
Recently I came across NetBeans, which is now free and developed by Sun. Sun seem to abandon all own IDE projects in favour of NetBeans, so this is a somehow strong foundation.
Oh… 25Mb installer only for PHP version 😉 And… it is easy to use. Very. I would like to guide you through the creation of new symfony project in NetBeans.
Continue reading “Free opensource Symfony-friendly IDE: NetBeans 6.8”
I’d like to share my script, which I use on some production servers for quick database backup using mysql tools. People say, that I should use bash for that, but I prefer PHP 🙂
Script uses mysqldump for dumping databases and gzip for compressing backups. rm is run to ensure backups are not stored for too long.
Continue reading “[Linux, PHP] PHP script to backup all databases”
Hello. For purposes of writting scripts for converting data formats, I have constructed an array, that can be used to replace language codes by their names.
Continue reading “PHP Array of ISO 639-1 language codes => names.”
Browing internet, I found the term of “quine” which is the program, that prints it’s exact source code. I was curious, if I am able to write such software. This is what I was able to compose:
It is a small and quite simple quine, however, I spent about several hours understanding how quines work and how to write them in PHP 🙂
Recently I needed to quickly change charset on all tables and change each field’s chanset in each table in a specific database to latin1 and collation to latin1_swedish_ci. I googled a little and found this solution by shimon doodkin. I used it and it did work, but also it attempted to change charset at MySQL information_schema system database which is something I didn’t want to. It also proceessed all databases at MySQL server. Luckily, there was only two 🙂 It was a test server, that’s why I was uncareful.
Ok. I wrote a bit more elegant solution I would like to share with you today. It is pretty self-explanatory and is based on ALTER TABLE CONVERT TO charset MySQL statement.
Continue reading “[PHP, MySQL] Batch changing charset and collation on databases”
As you probably know, latest software versions are rarely available to be installed as rpms. So, you need to compile them yourself. In this article I will briefly describe a process of installing, configuring and upgrading latest Apache and PHP.
Please remember, that installing from sources can sometimes break working system. So, please use this guide carefully.
Continue reading “[Linux] Installing latest Apache, PHP and MySQL from sources”
My approach to writting mid-to-huge applications is to put each class to separate file and autoload class files on demand to eliminate the use of include/require statements completely. Autoloading in some cases can even speed up your project (for example, my scripts rarely throw exceptions. Exception classes are loaded by demand and only in case exception happend, so I remove
overhead from my project. However, writting a good universal autoloader class is not trivial, however, simple. In this article I would like to suggest my own lightweigh multifunctional autoloader class.
Continue reading “[PHP] Writting Custom Class Autoloader Using SPL”
Now PDO is most promising database access mechanism in PHP5. However, using PDO natively is not always convinient. In this article I will suggest my own lightweight wrapper for PDO calls, which simplyfies things for me. I am PHP5 fan, so we will use all object oriented technologies this language can give us in constructing our PDO wrapper.
Continue reading “[PHP] PDO: Wrapping and making sweet”
As you know, each time php script is executed, PHP interpreter need to compile it first to bytecode and only after that – execute. That compilation takes much time.
APC PHP extension (which will be included and enabled in PHP6 by default. It becomes a standard) can speedup php script execution process by caching once compiled PHP bytecode in memory. So, installing this extension increases your server performance (we assume you are doing this at CPanel/WHM controlled server). To install extension just do the following:
Continue reading “[Linux] Decreasing server CPU load with PHP APC cache extension”