Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tomas Votruba:
4 Ways to Add Global Option or Argument to Symfony Console Application
Sep 04, 2018 @ 14:49:49

Tomas Votruba has a new post to his site showing you how to add a global option or argument to your application that makes use of the Symfony Console component. In this case, a "global" option is one that can be given to any command in the application. For his needs, it's a filename.

I'm working on 3 Console Commands. All was good, until I needed to add an argument to all commands at once... and in lazy, extensible, maintainable way.

He starts by talking about some of the "why" behind the need to run multiple commands at once. He shows an example of having multiple CHANGELOG files and the need to define the output file for each rather than just one file. He then goes through four different possible implementations, including the code and pros/cons of the approach:

  • Add Argument to Each Command
  • Modify Application Definition
  • The Symfony Event Subscriber Way
  • Extend the Application

He ends the post mentioning the one he prefers (the last one on the list) and briefly mentions anti-patterns and finding the right solution over just the first one you find.

tagged: symfony console application option global changelog tutorial

Link: https://www.tomasvotruba.cz/blog/2018/09/03/4-ways-to-add-global-option-or-argument-to-symfony-console-application/

Stovepipe Systems:
Using bitwise instead of booleans
Aug 18, 2016 @ 16:18:44

On the Stovepipe Systems blog there's a new post from Yannick de Lange that suggests using bitwose operations instead of booleans to evaluate an on/off setting.

The naive way of storing many boolean options (in a database) is to create for each option a field and storing a 0 when it is false and 1 when it is true. Which of course works, but adding options will require a new field, which might require creating a compatibility layer for your old data. There is an easier way to do this and it's even more efficient at checking fields.

This brings me to an old topic which I have to explain to all the new people at some point and even once explained not everybody understands how it actually works. So in this post I'm going to explain how to use bitwise operators and how it works internally.

He starts with a common example using the 0/1 storage method and refactors it a bit to use different values that are more compatible with bitwise operations. He includes the usage of this system and how to works to evaluate multiple potential option values.

tagged: bitwise option boolean storage enable setting tutorial

Link: http://stovepipe.systems/post/using-bitwise-instead-of-booleans

Symfony Blog:
PHP-PM grows up to be a credible option for high performance PHP
Apr 25, 2016 @ 17:29:58

On the Symfony Finland site there's a post about a relatively new way to run PHP applications and how it's "growing up" to become a viable option: PHP-PM.

PHP-PM is a novel way of running PHP applications. Instead of creating an exotic high performance runtime for the PHP language, it takes an alternative route to mechanism of running PHP applications with existing runtimes.

This translates to real performance gains with existing complex applications, not just impressive theoretical benchmark results.

Instead of the usual complete bootstrap that normal PHP process goes through in its lifecycle, PHP-PM runs them as a continuous process, making for a huge boost in overall performance. The project has started gathering more momentum and is being worked on to make it a more credible platform for PHP applications.

From the humble beginnings the PHP-PM now has over 1700 stars on GitHub and a number of developers working on it. Great strides have been done since the early stages with the documentation and ease of use, but most importantly the platform now supports multiple frameworks: Symfony, Zend and Laravel.
tagged: phppm process option high performance application project symfony

Link: https://www.symfony.fi/entry/php-pm-grows-up-to-be-a-credible-option-for-high-performance-php

Rob Allen:
Configuration in Slim Framework
Mar 16, 2016 @ 17:30:10

If you're a Slim framework user you should check out the latest post on Rob Allen's site covering all things configuration in using the framework and it's simple configuration handling.

Configuration in Slim Framework is nice and simple: the App's constructor takes a configuration array for the DI container.

He shows how to pass in the configuration as a optional constructor parameter on the main application, including a settings value containing some of the common options. These include the displayErrorDetails flag to show/hide detailed error messages and a logger setup (in his example Monolog). He also shows how to:

  • get settings from the configuration
  • use a separate file for the configuration
  • using a .env configuration file
  • combining multiple configuration files

He includes code examples for each of these cases as well as a method for using a non-array structure (like YAML or XML) via the ZendConfig component.

tagged: slim slim3 slimframework configuration option tutorial settings

Link: https://akrabat.com/configuration-in-slim-framework/

Lorna Mitchell:
Handling Composer "lock file out of date" Warning
Jan 22, 2016 @ 15:48:23

Lorna Mitchell has a post on her site that wants to help you out when Composer reports a "lock file out of date" warning when you try to update your Composer dependencies. She provides three options to help resolve this issue.

Composer is dependency management for PHP, and it consists of two main files: [composer.json and composer.lock]. Crucially, the composer.lock also includes a hash of the current composer.json when it updates, so you can always tell if you've added a requirement to the composer.json file and forgotten to install it.

The post includes three different ways to correct the warning message:

  • Option one: upgrade all of the things
  • Option two: try to work out which composer.json change caused this
  • Option three: do nothing, safely

The first two options are preferable to the last one (essentially overriding the error) but it could be used in cases where you think Composer is just getting things wrong.

tagged: composer lock file outofdate warning option fix override

Link: http://www.lornajane.net/posts/2016/handling-composer-lock-file-out-of-date-warning

SitePoint PHP Blog:
4 Best Chart Generation Options with PHP Components
Jun 26, 2015 @ 13:30:29

The SitePoint PHP blog has a new article posted sharing four of the best charting libraries they've seen for use in your PHP applications. Options include both server and client side tools, making finding one for your situation easier.

Data is everywhere around us, but it is boring to deal with raw data alone. That’s where visualization comes into the picture. [...] So, if you are dealing with data and are not already using some kind of charting component, there is a good chance that you are going to need one soon. That’s the reason I decided to make a list of libraries that will make the task of visualizing data easier for you.

He starts with a brief comparison of the server side versus client side options, pointing out some high level advantages and disadvantages of each. He then gets into each of the libraries, giving an overview, an output example and some sample code to get you started:

  • Google Charts (Client Side)
  • FusionCharts (Client Side)
  • pChart (Server Side)
  • ChartLogix PHP Graphs (Server Side)

He ends with a wrapup of the options and links to two other possibilities you could also evaluate to find the best fit.

tagged: chart generation option component top4 list example output code

Link: http://www.sitepoint.com/4-best-chart-generation-options-php-components/

Matthias Noback:
Symfony2: Add a global option to console commands and generate a PID file
Nov 26, 2013 @ 20:06:11

Cal Evans has pointed out a post by Matthias Noback related to Cal's "Signaling PHP" book and an idea presented in one of the appendices - working with PID files as a global option. Mattias writes:

Recently I read the book Signaling PHP by Cal Evans. It’s a short book, yet very affordable and it learned me a couple of things. First of all it explains about how you can “capture” a Ctrl+C on your long-running command and do some necessary cleanup work before actually terminating the application. In the appendix it also mentioned the interesting concept of a PID file. [...] In Appendix A of “Signaling PHP”, Cal writes about a way to extend a Symfony command to automatically create such a PID file before executing its task, and to delete this file afterwards.

Mattias shares what he calls a "hack" to make it happen globally - using the eventing system built into the Symfony Console functionality and the "console.command" event. He creates a bundle to help with the reading/writing of the PID file and shows how to implement it as a part of the event handling. He does point out one problem with this method (that the "input" object isn't available) so he works around it with the "ArgvInput" component and some manual handling to grab the PID file location provided.

tagged: symfony2 console option command pid file tutorial bundle

Link: http://php-and-symfony.matthiasnoback.nl/2013/11/symfony2-add-a-global-option-to-console-commands-and-generate-pid-file/

Anthony Ferrara:
Failure Is Always An Option - Programming With Anthony
Apr 01, 2013 @ 14:03:19

Anthony Ferrara has posted another video in his "Programming with Anthony" series, this time pointing out that failure is always an option.

A few days ago, I posted a video about how to become a better developer. There were a few interesting comments made, but one in particular from the Reddit threadpeaked my interest. So I decided to do a reply.

You can watch the video either in his blog or over on Youtube. He's also included the some of the contents of the Reddit post and a funny (relevant) comic about learning "C++ in 21 days".

tagged: failure option video programming youtube reddit

Link:

Christer Edvartsen's Blog:
Running Multiple Versions of PHPUnit
Dec 05, 2011 @ 18:26:18

Christer Edvartsen has a recent post showing you how to get multiple PHPUnit versions installed and working on your application. There's been some issues lately due to some updates in recent PHPUnit versions:

The latest version of PHPUnit (3.6.4 at the time of this writing) does not play well with the Zend Framework extensions (Zend_Test_PHPUnit). After asking Matthew Weier O'Phinney about this he answered that they had standardized on PHPUnit-3.4 for ZF1. Having just upgraded to the latest version of PHPUnit on our servers we were no longer able to test our Zend Framework applications. One option was to downgrade PHPUnit, but since we were already using some of the new features this was not going to happen.

He method uses the "installroot" option that can be passed in to the PHPUnit installation process to point it to someplace other than the default PEAR install location. A small change is needed to the "phpunit" executable to have it correctly set the include path. Then it's just a matter of making a symlink to your "/usr/bin" directory pointing to the specific version.

tagged: multiple version phpunit unittest installroot option

Link:

Brian Swan's Blog:
SQL Server Driver for PHP Connection Options: Encrypt & Failover_Partner
Mar 11, 2011 @ 14:41:11

Brian Swan has posted two more in his "SQL Server Driver for PHP" series looking at some of the connection options that are available. In these two new articles he looks at the Failover_Partner and Encrypt options.

Database mirroring is primarily a software solution for increasing database availability. [...] When a PHP application connects to the primary server, the Failover_Partner connection option specifies the name of the server to which the application should connect if the primary server is not available.

[...] These two options, Encrypt and TrustServerCertificate, are often used together. The Encrypt option is used to specify whether or not the connection to the server is encrypted (the default is false). The TrustServerCertificate option is used to indicate whether the certificate on the SQL Server instance should be trusted (the default is false).

In both there's code examples showing the connection strings and what kinds of parameters you can pass to them. He also gives a few examples of scenarios when they might be useful.

tagged: connect sqlserver driver option failoverpartner encyrpt trustservercertificate

Link:


Trending Topics: