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.
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.
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”.