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

Sergey Zhuk:
Promise-Based Cache With ReactPHP
Sep 20, 2017 @ 15:11:55

Sergey Zhuk has written up a tutorial showing you how to implement promise-based caching with ReactPHP, a continuation of a previous post.

In the previous article, we have already touched caching (when caching DNS records). It is an asynchronous promise-based Cache Component. The idea behind this component is to provide a promise-based CacheInterface and instead of waiting for a result to be retrieved from a cache the client code gets a promise. If there is a value in a cache the fulfilled with this value promise is returned. If there is no value by a specified key the rejected promise returns.

He starts by defining the caching interface and how it would look in use to set/get a cache value. He shows how to update this with a "done" handler to output the value when the get is complete. He continues on showing how to use a fallback handler: either "otherwise" or "then". He also shows how these can be chained together to make more complex operations. The post ends with an example of this caching component in action and links to other library that use the same ideas.

tagged: promise cache reactphp get set tutorial component interface

Link: http://seregazhuk.github.io/2017/09/15/reactphp-cache/

Sherif Ramadan:
Bloom Filters in PHP
Jun 22, 2016 @ 15:56:26

On his site Sherif Ramadan has posted an interesting tutorial covering implementing bloom filters in PHP. Bloom filters are data structures that make it easier to determine if something is a member of a set.

Let's imagine you have built a music app like Spotify. You've finally grown this thing to sizeable amount of users and you have a decent number of titles in your content library. Let's also say this app has social elements to it so your users can connect with their facebook friends or twitter followers. Now, let's say each time your users play a song in your app you want to ask the question Which of this user's friends have NOT listened to this song yet? The intention being that you may recommend that song to them if they haven't listened to it.

One solution to this problem is to use a data structure known as a bloom filter. A bloom filter is basically a very space-efficient hash set with probabilistic tendency. If you aren't familiar with a hash set or sets in general, let's do a quick review of what they mean.

He goes on to explain what a bloom filter is and how it differs from normal sets, hash sets and hash maps. He then introduces some of the basic concepts involved in creating and using bloom filters. To help make things clearer, he provides a "contrived example" using lightbulbs and the probably that they've been turned on. From there he starts to get into something more practical, something more in the world of PHP. He includes a basic Bloomfilter class example and some of the results (performance) of using it over something like in_array (especially for large data sets).

tagged: bloom filter example tutorial introduction probability set

Link: http://phpden.info/Bloom-filters-in-PHP

Kevin Schroeder:
Excluding Fields in the MongoDB/MongoDB Library
Mar 31, 2016 @ 16:18:05

In this new post to his site Kevin Schroeder has shared a helpful hint around the MongoDB library and excluding fields from the results of a query.

I am using the mongodb/mongodb library for a project of mine. The API seems fairly different from the old PECL library and it also came with some other, albeit unexpected, baggage. [...] One of the practices I’ve heard about Mongo is to get Mongo to do as much as it can, but not to worry too much about complicated joins and such as you would in SQL. In other words, don’t shy away from bringing data into the application to do some processing. That was the practice I followed, which worked fine up until my data size started to increase.

He started seeing some major performance issues when his data set grew to a significant size (50% of the response time). He went searching for a solution, tried MapReduce but eventually came upon an optional parameter letting him tell the Mongo DB to omit a value (or values) from the result set. Using this he dropped 7.5 seconds off of his wall clock time.

tagged: exclude fields result set mongodb library example parameter

Link: http://www.eschrade.com/page/excluding-fields-in-the-mongodbmongodb-library/

Woody Gilk:
Immutable Data Structures in PHP
Sep 23, 2015 @ 16:48:34

Woody Gilk has posted an article to his site looking at immutable data structures in PHP and a library that's come from the research and work he did to implement them in PHP.

As someone who most often works with PHP I often find myself envious of the more advanced data structures that are present in a language like Python. As an experiment, I decided to see if it would be possible to bring some of those basic structures to PHP while also preserving immutability. The result of this experiment is Destrukt.

He starts off talking about immutable data structures and introducing some of the basic concepts and usage around them. He notes that they "cannot be modified by accident" and how, if they do need to be changed, they'd actually be reassigned not updated. He then talks about PHP arrays, how they're normally used in PHP and how their flexibility can lead to potential issues in the code. His library implements more strict versions of the same functionality in the form of dictionaries, orderedlists, unorderedlists and sets. He includes examples of using the library to create these objects and how to get the data back out of them for evaluation.

tagged: immutable data structure introduction destrukt dictionary orderedlist unorderedlist set

Link: http://shadowhand.me/immutable-data-structures-in-php/

BitExpert Blog:
Think About It: Loop Iteration Per
Jul 15, 2015 @ 14:30:16

On the BitExpert.com blog Florian Horn continues his "Think About It" series (part 2) looking at performance enhancements that can be made when using the PHPExcel library and in their overall data processing. In this article they build on part one and share a few more handy performance tweaks.

This article is the second of a three-part series and describes how we optimized our data processing and reached performance improvements tweaking our code. Make sure you covered the first article about how we tweaked PHPExcel to run faster while reading Excel and CSV files.

He shows how they replaced some repeated looping and generating entities with an index-cached set. This set uses the ID of the element as the index and makes it faster and easier to reference the value. This dropped their overall loop handling of the imported data by half.

tagged: phpexcel performance update tweak part2 series indexcached set

Link: https://blog.bitexpert.de/blog/think-about-it-loop-iteration-performance-part-2/

Three Devs & A Maybe Podcast:
Understanding Character Sets and Encodings
May 14, 2014 @ 18:12:06

The Three Devs & A Maybe podcast (with hosts Michael Budd, Fraser Hart, Lewis Cains and Edd Mann) has posted their latest episode (#24) talking about character sets and encodings.

Having only just recently been bit by the character encoding issue again, we thought it would be a good time to bring it up on the podcast. Starting from the beginning with ASCII, we move on to discuss how 8-bit compatible machines brought way to the ISO-8859-* standards. This leads us on to Unicode, with the goal to develop a single character-set encoding standard that could support all of the world's scripts. Finally, we discuss the de-factor character encoding implementation used on the web today 'UTF-8', and reasons why this is the case.

Lots of different topics are mentioned including reversing a Unicode String in PHP using UTF-16BE/LE, portable UTF-8 and a YouTube video covering Pragmatic Unicode. You can listen to this new episode though the in-page player, by downloading the mp3 or subscribing to their feed.

tagged: threedevsandamaybe podcast ep24 unicode character set encoding utf8

Link: http://threedevsandamaybe.com/posts/understanding-character-sets-and-encodings/

Mathias Verraes:
Value Objects and User Interfaces
Nov 18, 2013 @ 17:35:07

Mathias Verraes has a new post today with a response to an email he received about some comments on a recent Elephant in the Room podcast about Value Object usage. The question asks about usage of Value Objects, specifically when it comes to things like country information.

There’s nothing intrinsically wrong with modeling countries as entities and storing them in the database. But in most cases, that overcomplicating things. Countries don’t change often. When a country’s name changes, it is in fact, for all practical purposes, a new country. If a country one day does not exist anymore, you can’t simply change all addresses, because possibly the country was split into two countries. Whenever you have this kind of friction, there’s usually some missing concept screaming to be discovered.

He talks some about the concepts around the "country" data and some of the functional concerns around it (duplicate checking, validation of existence, etc). He takes the concept and breaks it out into two different concepts - the actual Value Object of a single country and an "AvailableCountries" set (and "AvailableCountryRepository").

tagged: value object country example registry set

Link: http://verraes.net/2013/11/value-objects-and-user-interfaces/

SitePoint PHP Blog:
Responsive Images Using Picturefill and PHP
Oct 10, 2013 @ 15:08:11

On the SitePoint PHP blog there's a new post from Lukas White showing you how to use the Picturefill plugin (Javascript) along with PHP to make responsive images.

One of the key challenges with responsive web design, and a subject of much discussion in recent years, is how to deal with images. Setting a max-width on image elements enables designers to allow their size to adapt to the page dimensions, but in itself that approach can lead to far bigger images being downloaded than are required. [...] You can use a similar approach [to "source sets" of images] straight away and in a cross-browser compatible manner by using Javascript; one such method is the Picturefill plugin. In essence, Picturefill allows you to specify different src attributes for an image, each image file corresponding to a different media query. Thus

The tutorial helps you create an application, powered by the Slim framework and the ImageMagick extension, for the basic structure. He then grabs the Picturefill library and drops them into place. Some sample code is also included showing how to create the HTML structure for the images and the Javascript to handle the switching.

tagged: responsive image picturefill tutorial resolution source set

Link: http://www.sitepoint.com/responsive-images-using-picturefill-php/

Chris Jones:
Using PHP and Oracle Database 12c Implicit Result Sets
Jul 26, 2013 @ 14:12:40

Chris Jones has a new post to his site showing you how to use Oracle 12c's implicit result sets in your code. Note: this functionality is still in development, so the naming/exact functionality might change.

The new Oracle Database 12c "Implicit Result Sets" (IRS) feature allows query results to be returned from a stored PL/SQL procedure (or a PL/SQL anonymous block) without requiring special PHP code. Support for IRS is available in PHP OCI8 2.0.0-devel extension when it is compiled and used with Oracle Database 12c. (OCI8 2.0 can be compiled and used with other versions of Oracle Database but the available feature set is reduced).

He shows a normal fetch loop that calls the oci_* functions and grabs each row with a oci_fetch_row call. He updates this to use an anonymous PL/SQL block (a string) instead that allows for more flexibility. He includes examples that fetch from one table, multiple tables and returns multiple result sets (that can be fetched one at a time) from the same single call.

tagged: implicit result set oracle 12c tutorial multiple single sql plsql

Link: https://blogs.oracle.com/opal/entry/using_php_oci8_2_0

Web Developer Juice:
PHP Magic Functions: Best Part of Object Oriented PHP - Part 2
May 19, 2011 @ 15:14:27

Web Developer Juice has posted the second part of their series looking at some of the "magic functions" that PHP has to offer - special functions that do automagic things in your scripts and classes. Part one can be found here.

In my previous post ( PHP Magic Functions ), I discussed about __construct, __destruct, __call and __callStatic. Lets explore a few more magic functions...

In this latest part of the series they look at three functions:

  • __set/__get
  • __invoke
tagged: magic function method oop get set invoke

Link:


Trending Topics: