Skip to content

Blog

Objects and references in memory in PHP

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.

ImprovedCode, a new plug-in for TinyMCE

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.

JavaScript: difference between null and undefined

Programming in JavaScript, surely all we ever found us in the position of having to execute either a block of code or another depending on whether a variable is “null” or “undefined.” Today we will analyze the difference in JavaScript between “null” and “undefined“, since we have to be very careful when we compare them. “undefined” in JavaScript First, in order to speak about null and undefined in Javascript we need to clarify that “undefined” is a data type, as the Number, String, Boolean, Object or Array are data types as well. In Javascript, unlike other programming languages ​​with strong typing, we may have variables of type “undefined”. A priori, it may sound a little strange, but if you think about it for a moment,… Read More »JavaScript: difference between null and undefined

How to parallelize processes in PHP

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.
Read More »How to parallelize processes in PHP

HMVC: Modular applications in CodeIgniter

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:

core
third_party

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.
Read More »HMVC: Modular applications in CodeIgniter

How to distinguish uppercase, lowercase and UTF-8 characters in MySQL

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”.
Read More »How to distinguish uppercase, lowercase and UTF-8 characters in MySQL

JavaScript and CSS minified with Carabiner in CodeIgniter

Today we will talk about a powerful library available for the framework CodeIgniter, it is: Carabiner. This library allows us to include specifically for each view of our site the JavaScript and CSS files that are needed, avoiding to have to include them all at once, and also it sends them to the user in only one single file .”js” and one “.css” with all that we have including before but minified, so the size of the “.js” and “.css” that are sent to the user is much lower, with the improvement of loading time of the site that this implies.

Installing Carabiner in our project

The first thing we need for installing Carabiner in our CodeIgniter project is to download it. We can download it from the CodeIgniter forum. In order to install it, we simply have to place the files “carabiner.php”, “jsmin.php” and “cssmin.php” files into the directory /application/libraries of your project. Once this is done, we have to place the configuration file “carabiner.php” into the directory /application/config. In this file we have to specify the path to the directories that contain our files “.js” and “.css”.
Read More »JavaScript and CSS minified with Carabiner in CodeIgniter

Upload progress bar in CodeIgniter without Flash

Today we will see how we can create a progress bar file upload in CodeIgniter without the need for libraries or plug-ins made with Flash (like SWFUpload) that are beyond our control, because usually these libraries offer us already compiled .swf files, so we can not change anything in them, just in case we have knowledge of programming in ActionScript 2 or 3.

First of all, we have to say that creating a progress bar file upload in PHP is not as easy as it seems. The first problem is that PHP versions prior to 5.2 do not provide the necessary tools to provide information about the file upload at every moment. The second problem is that AJAX, by itself, does not allow us to check the status of the file upload process, since, for obvious security reasons, JavaScript does not have access to files on the client operating system, so you need a “trick” using an iframe.
Read More »Upload progress bar in CodeIgniter without Flash

scrollTo: The jQuery plug-in and our CSS

The jQuery plug-in scrollTo (developed by Ariel Flesler) enables us to make our website to scroll (scrolling the vertical bar) to any item on our document we need, this way we can focus the user’s attention in that element each time the page is reloaded (for example, an entry in the left menu on our website), sparing the user from having to do it manually. On the website of the plug-in project you can find all (or almost all) the documentation that is needed to integrate it into your own project.

Bug fix in ImageFlow 1.3

Today we are going to fix a bug I found in updating ImageFlow, going from version 1.2.1 to 1.3. The new version is intended to solve, among other things, the problem that was in Internet Explorer when there was only one image in the gallery. The problem was that nothing was showed if only we had a picture in the gallery in IE. Well, version 1.3 already displays the picture if we only have one, but if that image also has a caption, it turns out that the caption is not shown, nor Internet Explorer or any other browser . Well, here is the solution for those wishing to fix the bug (and are brave enough) and want to get their hands on the code of the library.