Today we will talk about how PHP creates objects in memory when performing a statement like $a = new Foo(); and how the references are managed in memory, since this is an issue that can generate discussion and difference of opinions. For that, we are going to talk about what references are NOT in PHP. Finally, we will talk about how the garbage collector works in PHP.
Today, we are going to talk about the TinyMCE plug-in “ImprovedCode”, which allows you to check the HTML source code of your page like the original one allows you, but with more interesting features, like highlighting of the code, autoindention, line numbers and more.
Today we will explain how to fork a process in our PHP scripts, so, we can parallelize processes that have a big load for the processor or simply they can be launched in parallel since they do not have dependencies between them and all of them solve partially a common task.
Why do we need to parallelize processes?
When we develop and algorithm, depending on the language that we use to programm it, we can solve the parts of the algorithm sequentially or in parallel. If we have a section of the algorithm which has a big processing load and requires a long time for its resolution, we could solve other parts while the slowest part of the algorithm is being solved. So, the total running time of our algorithm goes from being the sum of the parts to only the slowest part. It is true that we can only take advantage from parallelization when we have redundant resources (e.g: processors), but most of the existing servers have multiple cores, so it has enough income to learn to parallelize our processes.
Today we will make an introduction to how to create modular applications in the framework CodeIgniter using the HMVC extension (Hierarchical Model View Controller), so that our application gains in flexibility and we can split the project in parts that could be developed in parallel between multiple developers once the modules have been designed, with the valuable time saved to finish the project. HMVC allows us to have the same functionality offered by the “Bundles” in Symfony2 or the modules in the ZendFramework2.
Installing HMVC in CodeIgniter
The first thing we need to do in order to modularize our application is to download the HMVC extension. Once we unzip it, we find two folders inside:
We put the “third_party” folder (as it is) inside the “application” folder of our CodeIgniter application. The final location of the core folder depends on the version of CodeIgniter that we have installed. Therefore, the contents of the folder “core” will be in:
application/core (if we have CodeIgniter 2.0 or superior)
If we have CodeIgniter 1.7.3:
into application/libraries we will put the content of the “core” folder (3 files)
Well, with this we have installed the extension that allows us to modularize our application, but we need a final step. Inside the “application” folder we must create a directory called “modules” (application/modules). This directory (as its name suggests) will contain all the modules that we will develop.
This time we will talk about how to build a simple query for selecting data in a MySQL database, of which charset was set to utf8_general_ci but we need to distinguish between data with, lets say, accents and data without accents (or others UTF-8 characters, like German umlauts), and going a little further, if possible that not distinguish between words that begin with uppercase or lowercase but have accents. Let’s see how we could implement it.
Defining our problem
Let us explain a little better what is our problem. We have a MySQL database where we have a table, for example, “users”, with several fields: id, name, etc. This database was created with utf8_general_ci charset. But what does this mean? Obviously, “utf8” stands for the charset that our database will manage. In second place we have “general”, which indicates that we are not going to a specific set of UTF-8 characters for any specific language (we could use “utf8_spanish_ci” for the character set of the Spanish language, so we couldn not use Chineese characters in that case), but generically UTF-8. Finally, “ci” means “Case Insensitive”, so that in our searches, the MySQL engine will not distinguish between “UPPERCASE”, “Uppercase” or “uppercase”. What is not so well known is that being Case Insensitive implies no distinction between Spanish accents or German umlauts, so that it does not distinguish between “ESPAÑA” or “España”.