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

Przemek Sobstel:
Preventing the Dogpile Effect
Aug 11, 2014 @ 16:47:28

Przemek Sobstel has a recent post investigating an interesting theory in caching of any kind of application, not just PHP ones. He looks at the dogpile effect: when a cache expires and the database or host cannot catch up with so many non-cached requests coming in.

Implementing caching in web apps seems to be simple. You check if value is cached. If it is, you fetch cached value from cache and serve it. If it’s not, you generate new value and store in cache for future requests. Simple like that. However, what if value expires and then you get hundreds of requests? It cannot be served from cache anymore, so your databases are hit with numerous processes trying to re-generate the value. And the more requests databases receive, the slower and less responsive they get. Load spikes. Until eventually they likely go down.

He recommends using something called a "semaphore lock" to help prevent this kind of issue from happening. This lock prevents the removal of any stale content until after one process has finished refreshing the requested data. Only once the lock is released are the other processes allows to serve the fresh data. He includes some PHP pseudo-code that illustrates the point: trying to fetch the content, checking for the lock and releasing it when the single process is done with the refresh. He includes a link to a full implementation as well. He's also written up a full library, Metaphore, that integrates this into a full caching system.

tagged: dogpile effect theory cache tutorial metaphore semaphore

Link: http://www.sobstel.org/blog/preventing-dogpile-effect/

Semaphoreapp.com:
Continuous Integration & Deployment of PHP applications from GitHub to Heroku
Jun 18, 2014 @ 16:35:21

The Semaphore site (a testing and deployment service) has posted a tutorial showing how to set up a continuous integration/deployment using their service, GitHub and Heroku for a PHP application.

The practice of continuous delivery is steadily gaining ground in the PHP community. [...] With PHP support being recently launched on both Semaphore and Heroku, you can set up a continuous delivery pipeline for your web application in a matter of minutes. In this post I will show you how to set up continuous integration and deployment for a simple Laravel web application through Semaphore. You can find the application’s source code on GitHub.

They walk you through the creation of the Heroku application, grabbing the API key and connecting the Semaphore account with GitHub. Once linked, you can select the repository and any build commands needed for deployment. Finally, they show how to configure the actual continuous version of the deployment and have it release after each successful build.

tagged: semaphore continuous deployment integration github heroku tutorial

Link: https://semaphoreapp.com/blog/2014/06/17/continuous-integration-deployment-php-with-github-semaphore-heroku.html

Jonathan Hill:
Video: Multi-tasking in PHP (from Atlanta PHP)
Dec 28, 2012 @ 17:33:15

Jonathan Hill has posted the video of his recent presentation at the Atlanta PHP User Group, "Multi-tasking in PHP".

When it comes to multi-tasking and interacting with the operating system, PHP is no lightweight. In this December 6, 2012 presentation Jonathon Hill (@compwright) explores PHP's little-known POSIX, Process Control, and Semaphore extensions and shows you how to introduce a parallel dimension to your applications.

His presentation covers the use of multi-tasking to accomplish some common tasks in PHP (like batch processing or creating daemons). He talks about multi-processing vs multi-threading, forking, race conditions and semaphores.

You can watch the video of the presentation over on Vimeo and check out the software and links to other resources mentioned in the talk in this link bundle.

tagged: video multitasking fork threading semaphore links

Link:

Jonathan Hill:
What Is Wrong With PHP's Semaphore Extension
Dec 14, 2012 @ 17:08:18

In this recent post to his site Jonathan Hill takes a look at the PHP semaphore extension and talks about some of the issues he's had with it.

He lists five different pain points he discovered when trying to use the extension:

  • Lack of a true Semaphore
  • Undefined error handling
  • Undefined behavior of sem_get()
  • Cannot disable semaphore auto-releasing
  • A semaphore may be deleted when other processes are waiting to acquire it

The semaphore extension provides a PHP-based wrapper for the System V IPC family of functions (including semaphores, shared memory and inter-process messaging).

tagged: issues semaphore extension systemv functionality

Link:

Dave Marshall's Blog:
Defending against Cache Stampedes
Jan 13, 2012 @ 19:13:08

Dave Marshall has a new post to his blog showing one method for defending against cache stampedes from assaulting your caching servers and (possibly) bringing them down.

I’ve recently had a problem with a rather large operation (that could probably be optimised considerably, but nevermind), where by if the cached result of the operation expired, several web server threads would attempt the operation, causing some major headaches for our database and web servers. This is something I’ve come across before, and is commonly(?) known as a Cache Stampede. This is bad, this post describes the basics of what I’ve done to deal with it.

His example uses a Zend_Cache interface to Memecache, but it could be applied in other places too. His method uses a binary semaphore to check and see if there's a "lock" and sleep for a bit before checking again. Sample code is included showing how to create this system and how to refresh the data with a new expiration on a cache miss.

tagged: cache stampede zendcache tutorial binary semaphore miss prevention

Link:

Paul Reinheimer's Blog:
PHP BUG - err mm:core: failed to open semaphore file
Nov 11, 2009 @ 15:23:51

Paul Reinheimer came across a small bug in a recent PHP 5.2.x release of the language - a debugging message left in by mistake.

If you get an error when PHP launches along the lines of: "PHP Warning: PHP Startup: mm_create(0, /var/www/phpSessionStorage/session_mm_cli1000) failed, err mm:core: failed to open semaphore file (Permission denied) in Unknown on line 0" you're going to either need to upgrade to PHP 5.3.0 or wait for PHP 5.2.12.

It seems that some debugging code made it into the core code (but it's been corrected in the branches).

tagged: bug debug message semaphore error

Link:

Zend Developer Zone:
Zend Weekly Summaries Issue #322
Jan 29, 2007 @ 18:27:00

The latest weekly summary for the PHP mailing lists has been posted over on the Zend Developer Zone. This week, discussions included:

  • Sandboxed semaphores
  • Focus on *printf [continued]
  • PHP 5.2.1 RC2 and PHP 4.4.5 RC1
  • It's all in the HEAD
Descriptions of each of the headings are provided, including code and a "short version" for those on the run.

Be sure to check back each week for a new summary.

tagged: zend weekly summary semaphore fileinfo relrease fastcgi head openssl zend weekly summary semaphore fileinfo relrease fastcgi head openssl

Link:

Zend Developer Zone:
Zend Weekly Summaries Issue #322
Jan 29, 2007 @ 18:27:00

The latest weekly summary for the PHP mailing lists has been posted over on the Zend Developer Zone. This week, discussions included:

  • Sandboxed semaphores
  • Focus on *printf [continued]
  • PHP 5.2.1 RC2 and PHP 4.4.5 RC1
  • It's all in the HEAD
Descriptions of each of the headings are provided, including code and a "short version" for those on the run.

Be sure to check back each week for a new summary.

tagged: zend weekly summary semaphore fileinfo relrease fastcgi head openssl zend weekly summary semaphore fileinfo relrease fastcgi head openssl

Link:


Trending Topics: