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 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.
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”.
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.
In this post we will explain a little what it is and how we can use SWFUpload library in our application made with the php framework CodeIgniter, so that, our users can upload their files to the application in an elegant and visual way, and all combined with safety and ease that CodeIgniter offers for uploading files to the server.
What is SWFUpload?
Today we are going to explain how we can send a form via AJAX using jQuery in CodeIgniter, so we avoid to reload the whole page, giving the appearance of “desktop application” to our web application, being able to perform certain actions without reloading the entire page view.
Creating the form
First, we need to create our form. In this case we will create a generic form, where we will add different types of fields to make the example as complete as possible, but functionally not very helpful, mainly for teaching purposes… So in our view file in CodeIgniter we add the following code:
What is ImageFlow and what is it for?
In a previous post I talked about how to use the library PHPMailer to send emails from our website without having our own mail server running on the machine. This time we will go a step further and explain how to integrate this library in our CodeIgniter project and not die in the attempt.
The first thing we do, if we have not done it yet, will be to download the library. Once we unzip the library, we can rename the folder named PHPMailer and move it to the folder /system/application/libraries (for CodeIgniter 1.7.3 or previous) or to the folder /application/libraries/ (for CodeIgniter 2.0 or later) in our CodeIgniter application. Once we did it so, we can start to implement our own library, which will be in charge of including PHPMailer into our application. To do this we have to create a new PHP file in the CodeIgniter’s library directory called my_phpmailer.php. In this file we will write the following code:
What is JSON? What is it used for?