Lorna MitchellPHP 7.0 (and 5.6) on Ubuntu (11.2.2016, 10:07 UTC)

PHP 7 is released but for those of us who don't usually compile our own PHP, it can be a long wait for our preferred distro to release the packages we want. For Ubuntu, I'm using a PPA which allows both PHP 5.6 and PHP 7.0 to be installed, including things like extensions, at the same time. It was very easy to set up (I'm running Ubuntu 15.10 but this process should also work on older versions back to at least 14.04 which is the previous LTS) so here's a quick walkthrough of what I did.

Add the PPA

The PHP 5.6 and PHP 7.0 packages are from a third party PPA, not provided by the official ubuntu repositories from Canonical. The PPAs I'm recommending here are from Ondřej Surý who packages PHP for Debian (which is then used by Ubuntu) so while it's not an official repo, he's not exactly random! The PPA itself is here: https://launchpad.net/~ondrej/+archive/ubuntu/php

Complete aside but an important one: The work of the packagers is voluntary and they enable the rest of us to do whatever it is that we do. If you want us to keep being able to have nice things, consider the donation page for this project, please? https://deb.sury.org/pages/donate.html

To add the PPA to your setup:

sudo add-apt-repository ppa:ondrej/php

Then we'll also want to grab information about what is on offer from this new PPA, so then run:

sudo apt-get update

Install New PHP Versions

I already had some of the php5 packages installed, but I didn't uninstall anything, I just let apt work out what it wanted to do when I asked it to install the new versions:

sudo apt-get install php5.6 php7.0

This resulted in a lot of complaining from apt and lots of conflicts. The first suggested resolution was to remove all the stock php5 packages so that PHP 5.6 could be installed - so I just accepted the first suggestion.

I use apache so this setup gave me apache with both php5.6 and php7.0 modules available, and the php5.6 module actually loaded.

As well as just the PHP itself, all the extensions and other tools you'd expect with PHP are there for both versions of PHP so it's very easy to add in the modules that you need. I was very, very impressed with how nicely this is done.

Configuring and Switching Versions

Now you have two completely separate versions of PHP installed on your system, so let's have a look at where all the pieces went!

The config files are all in /etc/php/5.6 and /etc/php/7.0 respectively - inside here is where you can configure which extensions are loaded, set the ini settings, and everything else for each version in isolation.

I'm an apache user, and as I mentioned both modules are available. So to switch from one to the other I need to do:

sudo a2dismod php5.6
sudo a2enmod php7.0
sudo service apache2 restart

For nginx users, the changes are almost as easy, Digital Ocean have good documentation on this (they do have great docs!) so check out their guide: https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04 as it includes a section on reconfiguring nginx to use another version of PHP.

From the commandline, I have both php5.6 and php7.0 available as commands. I also still have a php command - look in /etc/alternatives to see that it symlinks to a particular version of PHP cli*. You can also quickly check which yours is using by running php -v.

* more specifically, run which php to see which version of PHP is being used - but this will probably point to /usr/bin/php, which for me is itself a symlink to the /etc/alternatives/php command.

Working with Extensions

This PPA comes with the usual php-pear package which offers the pecl command for both versions of PHP, so any extensions that are available via PECL can be installed in the usual way. You will also need the relevant headers so either php5.6-dev or php7.0-dev should be installed.

When the pecl installation completes, you'll get a note to add the *.so file to your php.ini; in fact the best thing to do here is to look at what's in /etc/php/mods-available. There will be some modules already here, each in its own file named after the extension and ending in .ini. You can copy one to use as a template or create your own and put all th

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

PHP ClassesPHP Tutorial to Increase Speed and Reduce Costs of AWS S3 using Caching (11.2.2016, 08:30 UTC)
By Joseluis Laso
Amazon S3 service is one of the most popular cloud storage services that you can use for many purposes like storing backups of important data or serve important files to many users.

Read this article to learn how to easily use Amazon AWS S3 API from PHP to store your files using caching to access the files faster and reducing the service costs.
SitePoint PHPBuilding an Spress Svbtle Theme – Responsive Static Blogs! (10.2.2016, 17:00 UTC)

You may have heard of Sculpin - a static site generator for PHP. Static blogs are, as you may know, blogs which you dynamically write in your app or on your local machine, and then export as a pure HTML version for hosting on static-only servers, for speed, reliability, and offline-first friendliness.

While easy to use and fast to set up, Sculpin’s development has stagnated a bit and the documentation leaves much to be desired. Spress is, in a way, its spritual successor. Much better documentation, much more flexible configuration, much easier to extend, and just as easy to use with almost the same API and commands.

Spress header image

In this tutorial, we’ll be building an Spress setup for generating a static blog with a custom theme.


This tutorial will assume you have a working PHP environment like Homestead Improved. For convenience, the following few lines will get you started immediately:

git clone https://github.com/swader/homestead_improved hi_spress
cd hi_spress
vagrant up; vagrant ssh

After we’re in the VM, we can install Spress with:

wget https://github.com/spress/Spress/releases/download/v2.0.0/spress.phar
sudo mv spress.phar /usr/local/bin/spress
sudo chmod +x /usr/local/bin/spress

Spress is now available system-wide (or VM-wide if you’re using a VM), which can be verified by running spress:

Screenshot of Spress output

To create a sample site, we can use the instructions from the docs:

cd ~/Code
spress site:new myblog spresso
cd myblog
spress site:build --server

The site should now be accessible via http://localhost:4000 or if you’re in a VM like Homestead Improved, you should first forward port 4000 in Homestead.yaml, run vagrant provision outside of the VM, and then access the site via http://homestead.app:4000:

Screenshot of working demo app

Continue reading %Building an Spress Svbtle Theme – Responsive Static Blogs!%

SitePoint PHPQuick Tip: Sync a Fork with the Original via GitHub’s Web UI (9.2.2016, 17:00 UTC)

I often find myself having to update my fork of someone else’s repo to include the changes made to the original since the fork. In fact, we use this approach often in SitePoint’s Peer Review System as well.

Purely by accident, I’ve recently discovered a way to quickly and easily sync a fork with the original repo through the Github web UI, so no need to go commando (use the command line).

Continue reading %Quick Tip: Sync a Fork with the Original via GitHub’s Web UI%

Voices of the ElePHPantInterview with Mathew Beane (9.2.2016, 05:00 UTC) Link
SitePoint PHPClean Code Architecture and Test Driven Development in PHP (8.2.2016, 18:00 UTC)

The Clean Code Architecture was introduced by Robert C. Martin on the 8light blog. The idea was to create an architecture which is independent of any external agency. Your business logic should not be coupled to a framework, a database, or to the web itself. With the independence, you have several advantages. For example, you have the ability to defer technical decisions to a later point during development (e.g. choosing a framework and choosing a database engine/provider). You can also easily switch the implementations or compare different implementations, but the biggest advantage is that your tests will run fast.

Just think about it. Do you really have to run through a router, load a database abstract layer or some ORM magic, or execute some other code just to assert one or more results?

I started to learn and practice this architecture because of my old favorite framework Kohana. At some point, the core developer stopped maintaining the code, which also meant that my projects would not get any further updates or security fixes. This meant that I had to either move to another framework and rewrite the entire project or trust the community development version.

Clean Code Architecture

I could have chosen to go with another framework. Maybe it would have been better to go with Symfony 1 or Zend 1, but by now that framework would have also changed.

Frameworks will continue to change and evolve. With composer, it is easy to install and replace packages, but it is also easy to abandon a package (composer even has the option to mark a package as abandoned), so it is easy to make “the wrong choice”.

In this tutorial, I will show you how we can implement the Clean Code Architecture in PHP, in order to be in control of our own logic, without being dependent on external providers, but while still using them. We will create a simple guestbook application.

Continue reading %Clean Code Architecture and Test Driven Development in PHP%

Thijs FerynBastian Hofmann – Talking about ResearchGate, Berlin & PHPBenelux (8.2.2016, 09:46 UTC)

Bastian Hofmann My friend Bastian Hofmann was flying to Brussels to speak at the PHPBenelux Conference that I organize. I

The post Bastian Hofmann – Talking about ResearchGate, Berlin & PHPBenelux appeared first on Thijs Feryn's blog.

nick halsteadThe technical reason Twitter cannot reorder Timeline (7.2.2016, 09:42 UTC)

I woke up to the news that Jack has denied that Twitter had plans to have a re-ordered timeline.

I was highly sceptical of that ever happening and it is for a purely technical reason. Now anything is of course ‘possible’ but Twitter has a particularly difficult problem when trying to do what Facebook does and it is the very reason Facebook sticks to 5000 friends.

Twitter has always allowed you to follow any number of people and over the years this has fundamentally been the core of most of it’s downtime, it is a very complex problem to deal with the idea that for every Tweet generated it must be distributed to potentially millions of users.

I don’t know the final solution Twitter used but I know it has taken many many years to evolve and develop bespoke software that can route Tweets between users who can have follow any number of other users, or be followed by any number of users.

And that is the problem, Facebook always kept a low limit because it’s fundamental design was that each time you refresh your timeline it basically does a complete re-render, I suspect that they rely upon the fact that they can first work out first a chronological list of updates from everyone you follow, and then they use the magic formula they use to re-order based upon your likes/priorities etc.

Twitter cannot do this – they allow you to follow an arbitrary number of other users – that means if you’re following 50,000 other accounts that means you need to do these calculations for every single update from those 50,000 accounts. If we assume every single account has Tweeted at least once (in last 24 hours) – that is 50,000 Tweets. I now must examine each Tweet, and rank it based upon it’s relevance to the user viewing – lets just look at what that ‘could’ involve.

  • Examine Tweet for subject matter (this could be pre-calculated)
  • Is the subject of interest to the user viewing (could be done by pre-caching subject relevance values)
  • Is the Tweet written by someone of importance? (remember Klout?)
  • Is the Tweet written by someone I interact with regularly (calculated either by number of @ mentions / or ‘retweets’ etc)
  • Does the Tweet contain a link that is important (based upon trending data – this is also likely cached)

Imagine the above 50,000 times for every time you want to view the timeline. Of course all things technical can be achieved – but Twitter has had 5+ years of making the current (very difficult) solution work, and how it currently works and how a re-ordered timeline needs to be calculated are not compatible in any shape or form.




Michelangelo van DamPHP Arrays - The php array functions (6.2.2016, 16:13 UTC)
Source: Xavier33300 on Flickr.com
In my previous article about arrays (the basicssimple operations and associative arrays or hash maps) I have shown what arrays are and what you can do with it. Now I want to dive into real fun and explain PHP's array functions with real-world examples and how you can apply them in your day-to-day work.

Collection to select form key-values

Many of the website registration forms uses a country select element or an autocomplete input field using data from a database.

If this was a single PHP with HTML combined page, there was no problem as you could easily reuse the query made to collect the data. But when using an MVC approach where your controller needs to push the data it fetches from the backend to the form before the form can be passed to the view you're in for a treat. We're addressing the issues for an MVC approach here.

Let's look at our country table first to get an impression how data is being stored in the database.

| Field     | Type        | Null | Key | Default | Extra          |
| id        | int(11)     | NO   | PRI | NULL    | auto_increment |
| iso       | char(2)     | NO   |     | NULL    |                |
| name      | varchar(80) | NO   |     | NULL    |                |
| nicename  | varchar(80) | NO   |     | NULL    |                |
| iso3      | char(3)     | YES  |     | NULL    |                |
| numcode   | smallint(6) | YES  |     | NULL    |                |
| phonecode | int(5)      | NO   |     | NULL    |                |

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

SitePoint PHP3 More Joins You Should Be Familiar With (5.2.2016, 17:00 UTC)

There are many ways to JOIN data from two database tables and filter the information you require. Craig Buckler wrote a popular piece on understanding JOINs; namely INNER, LEFT, RIGHT, and FULL OUTER. This article is an extension of that one.

Let’s recap these real quick. Picture two tables, one for customers and one for books to establish a book loan database.

customers table

id firstname lastname book_id
1 Joe Blow 1
2 Jane Doe 2
3 Harry Crow 2
4 Jeffrey Snow 0

books table

id Title
1 Star Wars
2 Jurassic Park
3 Little Women
4 Tom Sawyer

The books table has one row for every book.

The customers table has one row for each customer who can only have one book on loan at a time. If they have no book on loan, the book_id would be 0 or an empty string.

This is a very simple example to make the JOINs as clear as possible to understand!

A LEFT JOIN here would be in the case you want to ask a question such as “show me all customers including any books on loan.

Left Join Venn Diagram

You can see in the image that ALL data in the left circle, or table, is included in the result set. Only data that overlaps from the books table is included from the right table. This means that with a LEFT JOIN, some data in the right table may be excluded.

A RIGHT JOIN would be like asking “show me all the books in my library, along with any customers that have borrowed them.

Continue reading %3 More Joins You Should Be Familiar With%

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