SitePoint PHPIncrease Productivity with Komodo: an Extensible, Multi-language IDE (29.10.2014, 15:00 UTC)

This article is sponsored by Komodo IDE. Thank you for supporting the sponsors who make SitePoint possible!

As unglamorous as it sometimes is, it’s undeniable that most of a developer’s time is spent inside an editor, writing code. Think about it: You'll use your coding tool for hours every day at work, and then at home for coding side projects. That can be 30 hours a week, if not more.

With this in mind, it’s really important to make that editor space as comfortable, helpful, and useful as possible. To get to that point, you really need a reliable, well-established Integrated Development Environment, rather than just a code editor with syntax highlighting and a few simple plugins.

IDEs are much more than just code editors. They provide a whole development toolset. From code debuggers, integrated version control — supporting the most popular software such as Git, SVN, Mercurial — to unit testing environments, where you can have a framework automatically set up. Bonus points go to any IDE that can really let you make yourself at home, by allowing you to customize the environment to conform to the way you work best.

While most powerful IDEs boast some or all of these features, they’re often restricted to a specific platform. You’ll typically need to buy a license for each operating system you choose to develop in. A costly proposition, but fortunately not one that applies to all IDEs.

Komodo IDE stands out by offering a single license that can be used across all platforms — Windows, OS X and Linux — to develop a wide variety of languages. You don’t need to waste money buying a separate license key for each one, and you don’t need to worry about compatibility or being forced to put up with the particular quirks of one platform. Komodo also offers plenty of customization and extensibility, as well as top-notch version control and debugging services.

Komodo IDE website

In this article I’ll review Komodo IDE version 8, outline its features and advantages, and you’ll learn how this software can help you in writing better code and to be a more productive developer.

For the screenshots displayed below, I used Komodo’s “Abyss” skin after having customized Komodo to my liking.

How Komodo IDE can help you

Komodo IDE is a cross-platform IDE that supports most of the major programming languages in use today, such as PHP, Ruby, Node.js, and Python. The IDE also crosses the boundary into front-end, with support for HTML, CSS and JavaScript.

Its “cross-platform” nature means you can run the software on all major operating systems, OS X, Windows and Linux. This is nice if you work in a team and team members use different operating systems.

These cross-platform capabilities stem from Komodo’s implementation of the Mozilla engine, the same framework that powers equally-cross-platform browser Firefox.

More and more companies are making their software free for the open-source world and for educational institutions and ActiveState, the team behind Komodo IDE, is no different, with a range of licensing options available for individuals/freelancers, companies, and open source projects. Head over to the website and download a free trial.

ActiveState, the company behind Komodo IDE, also offers a free and open-source version of the software, cutting out all the advanced features, leaving you with a powerful, stripped-back code editor.

Key features of Komodo IDE

Komodo IDE has a balanced selection of features, with everything you’d expect from an IDE while avoiding becoming a software behemoth.

Besides the editor, the IDE has a debugger, a "toolbox" version control system integration, team collaboration, and powerful code intelligence with autocomplete and intelligent code refactoring.

Debugger

Debugger

Komodo has a powerful debugging engine with all the features you’d expect, such as viewing the call stack, breakpoints, remote debugging, and an interactive shell.

To start the debugger go to Debug -> Go/Continue or Debug -> Step In. By default the Debug Options window will appear, where you can configure the debugger environment, like select the programming language, set up environment variables or insert additional arguments.

Currently Komodo supports Perl

Truncated by Planet PHP, read more at the original (another 2377 bytes)

Link
Pascal MartinPHP versions statistics - October 2014 (29.10.2014, 06:00 UTC)

Cet article est aussi disponible en français.

You can follow me @pascal_martin, and there is an RSS feed of the posts I write in English.

I have collected data and written about usage of each PHP versions a few times already — up until now, always in French: this is the first time I’m doing this in English. The first time I’ve done this was in September 2011 and the most recent one was almost one year ago, in November 2013. At that time, PHP 5.2 was still representing 34.4% of PHP installations, with PHP 5.3 ahead with 48.7%.

The data presented in this post have been collected during the week-end of October 2014 18th. Stable versions of PHP are PHP 5.4.34 (which is called old-stable), PHP 5.5.18 and PHP 5.6.2. PHP 5.3 is not maintained anymore, since August 2014 14th and PHP 5.2 has been out of support for almost 4 years.


Web Servers

Before talking about PHP versions, here’s the list of web-servers I identified the most often while collecting data:

  • Apache: 5,644,243 — 58.65%
  • IIS: 1,496,967 — 15.56%
  • nginx: 1,410,170 — 14.65%
  • Others: 456,985 — 4.75%
  • GSE: 312,448 — 3.25%
  • cloudflare-nginx: 134,131 — 1.39%
  • LiteSpeed: 107,378 — 1.12%
  • Oversee Turing v1.0.0: 61,127 — 0.64%

As a graph only representing the first few results:

Apache is still in the first place — and by far — but it loses ground bit by bit, especially to nginx, which rose in one year from 7.9% to 14.8%. IIS remains at the second place, but could very well fall down one step before my next post!


Major versions of PHP

When it comes to major versions of PHP, there is no real surprise:

  • PHP 3: 415 — 0.02%
  • PHP 4: 106,866 — 4.15%
  • PHP 5: 2,470,731 — 95.84%
  • PHP 6: 36 — 0.00%
  • PHP 7: 3 — 0.00%

PHP 5 is first in line, far from the other versions1 — which is, let’s admit it, quite logical.

Still, a great number of servers are still running PHP 4 — its last version having been released in August 2008.


Minor versions of PHP

Going on with minor versions of PHP, for PHP >= 3.x and PHP <= 7.x and only keeping versions that have been detected at least 10 times, we’d get the following data:

  • PHP 3.0: 402 — 0.02%
  • PHP 3.2: 12 — 0.00%
  • PHP 4.0: 834 — 0.03%
  • PHP 4.1: 1,823 — 0.07%
  • PHP 4.2: 1,967 — 0.08%
  • PHP 4.3: 22,537 — 0.87%
  • PHP 4.4: 79,702 — 3.09%
  • PHP 5.0: 2,500 — 0.10%
  • PHP 5.1: 39,144 — 1.52%
  • PHP 5.2: 586,490 — 22.75%
  • PHP 5.3: 1,141,116 — 44.26%
  • PHP 5.4: 583,423 — 22.63%
  • PHP 5.5: 113,582 — 4.41%
  • PHP 5.6: 4,464 — 0.17%
  • PHP 6.0: 34 — 0.00%

And, as a graph:

Truncated by Planet PHP, read more at the original (another 19415 bytes)

Link
Ilia AlshanetskyZendCon - Deep Dive into Browser Performance (29.10.2014, 00:11 UTC)
My slides from ZendCon 2014 about "Deep Dive into Browser Performance" are now available for download here:
Slides
Link
Official Blog of the PEAR Group/PEAR PresidentSecurity Vulnerability Announcement (28.10.2014, 23:21 UTC)

A vulnerability in the HTML_AJAX package has been found which allows arbitrary remote code execution. All versions of the package from 0.4.0 up to and including release 0.5.6 are affected by this.

An new release of the package is available which fixes this issue. One is strongly encouraged to upgrade to it by using:

$ pear upgrade HTML_AJAX-0.5.7.

Link
Anna FilinaRE: How to Submit a Talk to a Conference (28.10.2014, 16:51 UTC)

I just read a very nice post by my friend Beth Tucker Long “How to Submit a Talk to a Conference“. Here are some additional thoughts.

Two thumbs up for “Identify a clear problem that the topic of your talk will help solve”. I read hundreds of proposals each year and nearly half of them fail to explain that. If it doesn’t explain this, it means that the presentation has no purpose and that it will just be a sequence of slides with bullet points, leading to death by PowerPoint (or live-coding, doesn’t matter). No goal = meaningless rambling. I have attended enough presentations to notice this pattern.

When I submit proposals, I start with the goal, then I figure out the title and the summary. When I write my presentation, I start with a slide about objectives. This guides me and forces me to abandon subtopics that do not contribute to reach these goals. For example: if my point is to show how easy it is to build responsive layouts, then I won’t attempt to cover every single feature of Bootstrap. It’s easy, but pointless. On the other hand, I might want to add a slide about common screen real-estate issues and their solutions, because that contributes to the objective.

There was another equally good article last month by Ross Tuck “Tips on Speaking” with some more in-depth advice that covers all stages of speaking.

Link
Anna FilinaReduce number of queries (28.10.2014, 15:24 UTC)

Customers often call me because their site is slow. One of the most common problems I found was a high number of queries that get executed for every single page hit. When I say a lot, I mean sometimes more than 1000 queries for a single page. This is often the case with a CMS which has been customized for the client’s specific needs.

In this article, aimed at beginner to intermediate developers, I will explain how to figure out whether the number of queries might be a problem, how to count them, how to find spots to optimize and how to eliminate most of these queries. I will focus specifically on number of queries, otherwise I could write a whole tome. I’ll provide code examples in PHP, but the advice applies to every language.

Start from the top

Start by looking at your browser’s inspector. I will demonstrate using Chrome. Open the inspector and reload the page. Click the Network tab and the first result will be the document generated by your script.

Inspector

You’ll notice that it takes 950 ms to load. Don’t stop there, check the breakdown of that time by hovering over the timeline bar to eliminate any doubt.

inspector-2

According to this chart, most of the time is spent by the server generating the page. The two most likely reasons are: you either use too much CPU (processing) or too much disk (files or database). Now that we narrowed the problem down a bit, it’s time to see whether we in fact have a lot of queries.

Count queries

If you’re using a CMS or a framework, then you probably have access to a single function that sends all the queries or even logs them. For example, with Moodle (a learning system used by many universities) you can call $DB->perf_get_queries() at the bottom of the page to output the number of queries executed. Check the documentation of your product to find these functions.

If all the code is your own, then wrap all database calls in a single function and add a counter. Example:

protected $num_queries = 0;
public function query_db($sql, $params) {
  $this->num_queries++;
  // execute here
}
public function get_num_queries() {
  return $this->num_queries;
}

My rule of thumb is to focus on pages that execute 10 or more queries. You can also log the individual queries in an array so that you can have access to a full list. This list will be helpful helpful to find which ones are very similar and can be combined.

One common reason for so many queries is executing them in a loop. For example, I often see a query for a list of Categories, a loop on these categories and then another query to get the list of Subcategories. Example:

$categories = get_categories();
foreach ($categories as $category) {
  $subcategories = get_categories($category->id);
}

Just here, there is a potential for dozens of queries. Sometimes, I see nested loops, where people would iterate on the subcategories to get the list of Courses. Now you’re probably up to 100 queries. Throw in a query to get some additional information for each Course, such as whether the user has completed them and you might be over 1000 queries.

Optimize

Once you get a log of all the queries that were executed, look for ones that look almost the same. Example:

select * from course_categories where parent = 0;
select * from course_categories where parent = 1;
select * from course_categories where parent = 3;
select * from course_categories where parent = 15;
select * from course_categories where parent = 22;

I can tell right away that the first query gets all top-level categories and we then iterate on them to get subcategories for each. The best way to fix this is to combine. You do this by executing a hand-crafted query in the code instead of relying on the built-in functions:

SELECT
cat.id AS cat_id, cat.parent, cat.name AS cat_name,
subcat.id AS subcat_id, subcat.parent, subcat.name AS subcat_name
FROM course_categories AS cat
LEFT JOIN course_categories AS subcat ON subcat.parent = cat.id
WHERE cat.parent = 0
ORDER BY subcat.parent;

This will fetch both the categories and their subcategories. It might look a bit complex, but I’m really just using table and column aliases. As a bonus, we only fetch the columns that we need instead of * (star), since getting data that we don’t need is just slowing things down. The results you get back will look like this:

+--------+--------------

Truncated by Planet PHP, read more at the original (another 2464 bytes)

Link
labs @ Qandidate.comAdding a unique request id using middleware (28.10.2014, 15:00 UTC)

In our event-sourced applications built using Broadway we have a full log of all events that happened in our application. We also log all commands using monolog. We did however miss some traceability between the commands and the actual events: we logged both the commands and the events but could not determine which commands led to which events.

In order to achieve this we decided to add a request id to each of our requests. We can now add the request id to the command log and add the request id to the metadata of our DomainMessages using the MetadataEnricherInterface

There are some webservers that provide a solution for this problem. One of these is an nginx module, and there is also an apache module. However, we wanted our solution to be webserver-independent. The result: we decided to tackle our problem the way we know best; in PHP.

We created a middleware for Symfony that adds a request id header to the request's headers. Check out the source code. You can add it to your application by changing a few lines of code in your app.php file. Just have a look at these 'before' and 'after' codeblocks:

∞ labs @ Qandidate.com Permalink

Link
Cal EvansInterview with Erika Heidi Reinaldo (28.10.2014, 05:00 UTC) Link
Anthony FerraraYou're Doing Agile Wrong (27.10.2014, 16:00 UTC)
To some of you, this may not be new. But to many of the people preaching "Agile Software Development", Agile is not what you think it is. Let me say that again, because it's important: You're Doing Agile Wrong.

Read more »
Link
Fabien PotencierThe PHP Security Advisories Database (26.10.2014, 07:07 UTC)

A year and a half ago, I was very proud to announce a new initiative to create a database of known security vulnerabilities for projects using Composer. It has been a great success so far; many people extended the database with their own advisories. As of today, we have vulnerabilities for Doctrine, DomPdf, Laravel, SabreDav, Swiftmailer, Twig, Yii, Zend Framework, and of course Symfony (we also have entries for some Symfony bundles like UserBundle, RestBundle, and JsTranslationBundle.)

The security checker is now included by default in all new Symfony project via sensiolabs/SensioDistributionBundle; checking vulnerabilities is as easy as it can get:

$ ./app/console security:check

If you are not using Symfony, you can easily use the web interface, the command line tool, or the HTTP API. And of course, you are free to build your own tool, based on the advisories stored in the "database".

Today, I've decided to get one step further and to clarify my intent with this database: I don't want the database to be controlled by me or SensioLabs, I want to help people find libraries they must upgrade now. That's the reason why I've added a LICENSE for the database, which is now into the public domain.

Also, even if I've been managing this database since the beginning with only good intentions, it is important that the data are not controlled by just one person. We need one centralized repository for all PHP libraries, but a distributed responsibility. As this repository is a good starting point, I've decided to move the repository from the SensioLabs organization to the FriendsOfPHP organization.

I hope that these changes will help the broader PHP community. So, who wants to help?

Link
LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP