PHPDeveloper.orghttp://www.phpdeveloper.org
Up-to-the Minute PHP News, views and communityen-usTue, 03 Mar 2015 16:48:48 -060030http://www.phpdeveloper.org/news/20514http://www.phpdeveloper.org/news/20514
In a new post to his site Ulf Wendel shows an alternative use for the PHP Memcache functions - using them to query MySQL tables (InnoDB) in much the same way. He also tosses in Redis as another version to compare the performance against (for fetching key/value pairs).

PHP users can use two client protocols to query MySQL 5.6 and later. Not only standard SQL access but also faster key-value access to InnoDB tables is possible using the Memcache protocol. The MySQL benchmark team reports crazy figures. Of course, on hardware that makes the average PHP meetup visitor roll his eyes and say "yeah, Oracle, *yawn*…". I've repeated my plain PHP benchmarks on an i3 desktop. And, I've added Redis to the game.

He goes through and compares a few different things with some simple benchmarks around operations per second:

MySQL 5.6 Memcache vs. MySQL 5.7 Memcache vs. Memcache vs. SQL

MySQL vs. Memcache vs. Redis

For each he's graphed out the results of the benchmarking with some surprising results for those that may thing MySQL isn't as suited as Redis for something like this.

Link: http://blog.ulf-wendel.de/2013/using-phps-memcache-interface-to-query-mysql-5-7/]]>Fri, 13 Dec 2013 12:56:50 -0600http://www.phpdeveloper.org/news/20383http://www.phpdeveloper.org/news/20383
DZone.com has posted the second part of a two-part series looking at increasing the performance of your PHP applications (part one is here). In this new post, he looks at a few topics including caching, session handling and asynchronous processing with Resque and Redis.

Ultimately, scalability is about the entire architecture, not some minor code optimizations. Often times people get this wrong and naively think they should focus on the edge cases. Solid architectural decisions like doing blocking work in the background via tasks, proactively caching expensive calls, and using a reverse proxy cache will get you much further than arguing about single quotes or double quotes.

He briefly recaps some of the "core principles" for optimizing applications and gets right into explaining the later ones on the list:

He includes code and configuration examples for each item, helping to flesh them out a bit more. He also makes a recommendation of using something like AppDynamics to monitor the performance of your application (disclaimer: he works for them).

Link: http://architects.dzone.com/articles/php-performance-crash-course-0]]>Wed, 13 Nov 2013 10:56:33 -0600http://www.phpdeveloper.org/news/20289http://www.phpdeveloper.org/news/20289
On VilkomenJuist.nl there's a recent post showing you how to create a real-time notification system with PHP using Laravel, NodeJs and Redis.

Currently I am building an application where we can fill in live scores and I needed something to update all my visitors whenever a score has been updated by one of the admins. Whenever an admin updates the score via the Laravel 4 backend I fire an event and publish it to Redis. I've setup a simple NodeJS server which listens to Redis for incoming changes. NodeJS will redirect the message to all Socket.IO clients.

The post has all of the code and configuration you'll need to reproduce the setup. This includes the Laravel Redis config, code for the event handler and the Node server listening for the socket connection.

Link: http://www.volkomenjuist.nl/blog/2013/10/20/laravel-4-and-nodejsredis-pubsub-realtime-notifications/]]>Wed, 23 Oct 2013 11:48:36 -0500http://www.phpdeveloper.org/news/19823http://www.phpdeveloper.org/news/19823
On PHPMaster.com today there's a new tutorial showing you how to store your application's sessions in Redis, a key/value store known for its flexible nature and speed.

PHP's default handling of session data is probably sufficient for most applications, but sometimes a project will demand a different storage approach. Luckily, the session handling routines can be overridden either by a series of functions (in older versions of PHP) or a class with methods (in newer versions) which handle various aspects of session management. In this article we'll learn how to create a custom session handler which implements PHP's SessionHandlerInterface interface and stores the session data in a Redis database.

He talks some about the reasoning behind using something more than just the normal PHP session handling (including the flexibility it provides). He covers some of the basics of the session handling functionality and covers how the data itself is stored. Finally, he gets to the actual class - a Redis-specific handler that implements the SessionHandlerInterface interface.

Link: http://phpmaster.com/saving-php-sessions-in-redis/]]>Tue, 09 Jul 2013 10:53:01 -0500http://www.phpdeveloper.org/news/19739http://www.phpdeveloper.org/news/19739
Aleksey Korzun has posted some of the results from benchmarking he performed on various Memcached and Redis clients through PHP. His tests focused on multiple PHP client libraries, both user-land and extension based.

As some of you may know, I'm crazy about speed. So when I saw that people were happily using Predis as their choice of PHP client for Redis, I was a bit confused. Why use a client written in PHP for something that should be 'fast' like Redis? That kind of defeats the purpose - unless you don't really care about response times and scalability. [...] The performance difference piqued my interest. I wanted to find out just how much performance users are sacrificing by choosing one implementation over another.

He ran his tests on VirtualBox VM instances with the same specs and the same version of PHP installed. He tested various versions of the Memcached client, Redis client, Predis and the IgBinary extension. His results (Google spreadsheet) show the requests processed using each method based on this benchmarking script.You can visit the post to see the graphs of the results too.

Link: http://alekseykorzun.com/post/53283070010/benchmarking-memcached-and-redis-clients]]>Wed, 19 Jun 2013 11:06:31 -0500http://www.phpdeveloper.org/news/19080http://www.phpdeveloper.org/news/19080
James Morris has an interesting new post to his site about the creation of a real-time web service that could be used for iOS applications via Websockets. He chose Ratchet for the handling (a PHP-based websocket tool) combined with Redis and Silex.

I was approached by a betting/gambling development company who potentially needed a middleware building that would pull from an existing gambling web service and basically transmit to connected iPhone clients the changes from the web service. At first, the obvious answer might be to create another REST web service that the iPhone clients could just ping for changes. However, one of the devs explained that this wouldn't be fast enough, or scale - they'd need changes to be transmitted as soon as possible, as the app would be a real-time betting app and there'd be thousands of connections to the server.

His solution involved hooking together Ratchet, Redis, Silex and Predis-async to create this sample tool for handling the websocket requests. it uses the "pubsub" mechanism of Redis to push the updates out to listening clients.

]]>Wed, 23 Jan 2013 12:09:33 -0600http://www.phpdeveloper.org/news/17901http://www.phpdeveloper.org/news/17901
On PHPMaster.com today there's a new tutorial by Daniel Gafitescu showing you how to work with Redis (a key-value store) via PHP with the help of the Predis library.

There is a lot of argument whether Redis or Memcache is better, though as the benchmarks show they perform pretty much on par with each other for basic operations. Redis has more features than Memcache has, such as in-memory and disk persistence, atomic commands and transactions, and not logging every change to disk but rather server-side data structures instead. In this article we'll take a look at some of the basic but powerful commands that Redis has to offer using the Predis library.

He helps you get a local redis server up and running and includes a link to the repository for the latest version of the Predis library. Some sample code is provided showing how to connect to the server, push data into a key/value combination, get the value back out, increment it and check to see if it exists. He also talks about some of the available data types Redis provides and a few other more complex operations you can perform on things other than strings.

]]>Thu, 03 May 2012 09:35:21 -0500http://www.phpdeveloper.org/news/17799http://www.phpdeveloper.org/news/17799
The Voices of the ElePHPant podcast has posted their latest episode - an interview with another member of the PHP community, Justin Carmony, a member of the Utah Open Source Foundation/Conference.

Cal's "three questions" for Justin are around his work with Redis and the Utah open source community and conference:

For those that don't know, can you tell us what Redis is and why did you choose it over other options?

Can you tell us why "middle-scale" sites are different and what challenges do they uniquely face?

As a developer how has getting involved in organizing helped you both personally and professionally?

]]>Tue, 10 Apr 2012 13:19:39 -0500http://www.phpdeveloper.org/news/17378http://www.phpdeveloper.org/news/17378
In this latest post to his blog Justin Carmony shares some of his experience using Redis and Solo to asynchronously run queries and return data without the user having to wait.

Sometimes there are situations when you want to parallel process things. Other times you might have a list of tasks to accomplish, and you don't want to make the user wait after pressing a button. This is where "Workers" can come in. They are independent scripts that run along side of your application, performing tasks, or "jobs."

Solo is a very basic Perl script that ensures only one process of a type is running at once. Using this and a PHP library called predis, he shows how to set up workers and add items to your processing queue. The workers themselves run on a cron job and connect to the queue server to see what they need to do. He also throws in some "bells and whistles" - extras that can enhance your worker system: queue monitoring, version numbering and killing workers based on a hash value.

]]>Wed, 11 Jan 2012 11:50:52 -0600http://www.phpdeveloper.org/news/16387http://www.phpdeveloper.org/news/16387
In a new post to his blog Justin Carmonyshares the story of how he took a platform running with MySQL as the backend (Dating DNA) and made the choice to move to Redis for storing compatibility scores for every user in the system.

We wanted not only for people to be able to visit a profile and see a score, which is easy to generate a score on demand. We wanted our users to be able to browse other profiles sorted by their score with them. This requires us to pre-generate and store these scores, and then later query them. [...] I believe we could have bent MySQL to our will and got it to work, but it would be at a high cost of server power, and that cost wouldn't scale well with our revenue stream.

He talks about some of the other options they sorted through including NoSQL databases or building something completely in-house. In the end, though, they decided that Redis was more of what they needed. He prefaces talking about their configuration with some of the limitations of the tool and then moves into their setup and statistics on its use (complete with pretty graphs). He points to predis as their Redis client of choice for PHP.