PHP assertions

When I hear the word “assertion”, the first thing that comes to my mind is PHPUnit assertions.  Sure, I write assertions in my unit tests.  But is that the only application?  Today I decided to figure it out, or, at least, learn more about the subject.

It turns out that PHP has assert() and assert_options() functions.  And those were there since the ancient times of PHP 4.  Sounds cool, but how useful are these?  Well, not that much:

Assertions should be used as a debugging feature only. You may use them for sanity-checks that test for conditions that should always be TRUE and that indicate some programming errors if not or to check for the presence of certain features like extension functions or certain system limits and features.

Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be able to work correctly if assertion checking is not activated.

This StackOverflow discussion expands a bit on the subject and concludes that assertions are just a developer tool used for troubleshooting and such. Bummer!

But I’m not that easily stopped.  Next stop – search for tools and libraries on GitHub and Packagist.  There’s more luck here!  A whole lot of different libraries exist that help with asserting facts and matching values to patterns.  I’ve checked a few of them and here’s the Top 3 List that I’m considering for use in my code:

  • beberlei/assert – simple to use library, with a respectable number of implemented assertions.  It supports chained methods, lazy assertions, and is easy to extend.  (See this blog post, announcing version 2 a few years back.) Also, the fact that almost 300 projects depend on it, makes it an attractive choice.
  • nilportugues/php-assert – also an easy to use library, which offers even more assertions, grouped into a number of categories (generic, string, integer, float, array, date and time, object, and file upload).  It’s not anywhere near as popular as the previous option, but that is probably just a question of time.
  • peridot-php/leo – a much more advanced assertion and matching library than the previous two options.  In fact, so much more advanced, that it has a dedicated documentation website.  This is understandable, as this library is a part of the Peridot BDD testing framework.  It is easy to extend too, but I’m not sure yet that I need that level of complexity in my projects.

I found a few more alternatives, but they looked like side projects or small toolboxes for specific needs.  None of those impressed me enough to be linked here.

It’s too late at night to make a decision right now on which project I like the most.  But I will definitely play more with the ones above.  If you have any experience with those or with any other assertion/matching library, I’m interested to hear.

 

Cyprus : startup visa proposal

CNA shares some interesting news:

A proposal promoting startups visa, aiming to attract entrepreneurs from non-EU countries will be submitted to the next meeting of the Council of Ministers for approval, Cyprus President Nicos Anastasiades has said.

Addressing a graduation ceremony of IDEA, a starup programme co-founded by Bank of Cyprus and CIIM, the President also announced that a proposal from the legal framework for university spinoffs, liking academic research with entrepreneurship will be tabled within the next three months.

“We believe that the Cypriot startup visa will be one of the most competitive and will bring multiple benefits in the medium-term both as regards new jobs as well as promoting innovation and research and the boosting the competitiveness of our economy,” the President said.

Of course, knowing how long things take in this country (especially if the government is involved) and how twisted they get by the implementation time, one shouldn’t hold one’s breath.  But there’s hope, if nothing else…

Maintainers Don’t Scale

Daniel Vetter, one of the Linux kernel maintainers, shares some thoughts on why maintainers don’t scale, what it takes to do the job, what has changed recently and what needs to change in the future.

This reminded me of this infographic, which depicts a year (even though back in 2012 – probably much busier these days) for another kernel maintainer – Greg Kroah-Hartman.  Note that the number of emails does not include the messages on the Linux kernel mailing list (LKML), which is in its own category of busy:

The Linux kernel mailing list (LKML) is the main electronic mailing list for Linux kernel development, where the majority of the announcements, discussions, debates, and flame wars over the kernel take place. Many other mailing lists exist to discuss the different subsystems and ports of the Linux kernel, but LKML is the principal communication channel among Linux kernel developers. It is a very high-volume list, usually receiving about 1,000 messages each day, most of which are kernel code patches.

Mcrouter: a memcached protocol router

Mcrouter is an Open Source tool developed by Facebook for scaling up the memcached deployments:

Mcrouter is a memcached protocol router for scaling memcached (http://memcached.org/) deployments. It’s a core component of cache infrastructure at Facebook and Instagram where mcrouter handles almost 5 billion requests per second at peak.

Here is a good overview of some of the scenarios where Mcrouter is useful.  There’s more than one.  Here are some of the features to get you started:

  • Memcached ASCII protocol
  • Connection pooling
  • Multiple hashing schemes
  • Prefix routing
  • Replicated pools
  • Production traffic shadowing
  • Online reconfiguration
  • Flexible routing
  • Destination health monitoring/automatic failover
  • Cold cache warm up
  • Broadcast operations
  • Reliable delete stream
  • Multi-cluster support
  • Rich stats and debug commands
  • Quality of service
  • Large values
  • Multi-level caches
  • IPv6 support
  • SSL support

Amazon AWS : MTU for EC2

I came across this handy Amazon AWS manual for the maximum transfer unit (MTU) configuration for EC2 instances.  This is not something one needs every day, but, I’m sure, when I need it, I’ll otherwise be spending hours trying to find it.

The maximum transmission unit (MTU) of a network connection is the size, in bytes, of the largest permissible packet that can be passed over the connection. The larger the MTU of a connection, the more data that can be passed in a single packet. Ethernet packets consist of the frame, or the actual data you are sending, and the network overhead information that surrounds it.

Ethernet frames can come in different formats, and the most common format is the standard Ethernet v2 frame format. It supports 1500 MTU, which is the largest Ethernet packet size supported over most of the Internet. The maximum supported MTU for an instance depends on its instance type. All Amazon EC2 instance types support 1500 MTU, and many current instance sizes support 9001 MTU, or jumbo frames.

The document goes into the detail of how to set, check and troubleshoot MTU on the EC2 instances, which instance types support jumbo frames,  when you should and shouldn’t change the MTU, etc.

The following instances support jumbo frames:

  • Compute optimized: C3, C4, CC2
  • General purpose: M3, M4, T2
  • Accelerated computing: CG1, G2, P2
  • Memory optimized: CR1, R3, R4, X1
  • Storage optimized: D2, HI1, HS1, I2

As always, Julia Evans has got you covered on the basics of networking and the MTU.