One of the things that I’m working on, requires creating and executing a lot of small PHP scripts. Sometimes it’s about code snippets, sometimes it’s a bunch of functions and methods that have to be tested. Of course the best way to work on your code is within your preferred IDE (I’m using CodeLite), but when we speak about bunch of small scripts, you cannot even call it a project. Since most of the work that we, web developers, is done on the browser, then why should we leave it to write code anyway? Hmm.. especially if it’s about small scripts.
PHP was not built as an asynchronous scripting language. Although it does support multiple processes (pcntl_* functions), it works on a very specific server configuration. However, if PHP does not support parallel execution, it doesn’t mean that we cannot do it manually.
I know that most of the PHP community and open source generally does not like commercial products, however, Zend’s Z-Ray will simplify the debugging and the profiling processes, and that’s what really important. And (!), it’s for free for open source projects. The preview alpha version is also for free.
Well, what is Z-Ray?
Z-Ray is a PHP extension that, for every request to the server, captures the database queries that were executed during the request, all the invoked functions, all the errors and exceptions with their backtrace, resources usage statistics, and more. The captured data is displayed either within an injected toolbar at the bottom of the page, or in “Z-Ray Live”, which displays data about all the incoming requests to the server, on a separate web page. The injected toolbar version of it looks like this:
Well, what is a closure? Closure is an anonymous function, aka lambda function, a function without a name within its scope. What it means? – Usually it’s used to pass a function as a callback argument to another function which expects to receive parameter from type “callable”.
Here’s an example of a lambda function that is passed to array_filter function
PHP is an OOP language, however, unlike C++, PHP classes cannot inherit from more than one base class. A class might implement several interfaces to cover some specific use cases, but this is absolutely another story. PHP introduced the traits in version 5.4.0. Still, this is not a native multiple inheritance, but it’s a nice feature that might fit many cases in which multiple inheritance is needed.
A trait is not a regular (or an abstract) class that you might want to extend, its definition and syntax are slightly different. The “base class” is defined as a trait from the very beginning, and the syntax is almost the same as for a class. It can be treated as, kind of, extensions for classes.
Let’s start with a simple trait example for error handling. The syntax and the definition of a trait is done in the next way
NoSql is becoming the new database standard. The top advantages of non-relational databases is the flexibility and the scalability, what makes it very useful for “big-data” services. One of the leading NoSql databases is MongoDB which is maintained by “10gen” (They provide courses, tutorials and certifications). This post is going to talk about the integration of PHP and MongoDB.
First, the terminology differs a little from RDBMS (relational databases). Tables become Collections because they don’t have a static structure, so calling them tables would be wrong. Rows become documents, because every document is a JSON object and might have different structure from one document to another.
Unit testing is very important, we all know that, and I assume that most of us are familiar with the popular PHP unit testing framework – PHPUnit. As any other framework it has its advantages and disadvantages, but what I didn’t like in it, is the installation process.. Definitely, the installation can be done manually, but I was looking for some simple and light testing framework for my application.
After a brief search on GitHub, I landed on a framework called Testify, which is very light, and provides good functionality. However…