2015年5月22日星期五

Site News: Popular Posts for the Week of 05.22.2015

Popular posts from PHPDeveloper.org for the past week:

Bigcommerce Engineering Blog: PHP Memory Optimization


On the Bigcommerce Engineering blog there's a new post sharing a few tips for memory optimization in your PHP applications. This includes tips you can implement at a code level without too many changes to the server or the need for external services.



Lately, I've been working on optimizing the memory of some of our backend PHP applications and wanted to share some of the tricks that I have come across, especially dealing with large set of data using PHP.

Each of their tips includes code to illustrate the technique:



  • Always cap your internal in-memory caching
  • Use layered caching
  • (Freeing) DB Resources
  • Free large blocks of memory


Some of the examples include output from the scripts showing the reduction (or non-growth) of the peak memory usage of the script.


Link: http://bigeng.io/post/119546277718/php-memory-optimization

NetTuts.com: Programming With Yii2: Timestamp Behavior


NetTuts.com has posted the next part of their "Programming with Yii2" tutorial series today. This new tutorial in the series focuses on the use of the timestamp behavior to assign the current date to an object (like for create or update dates).



In this tutorial, we'll explore Timestamp Behaviors, which reduce the amount of code you need to write with each new model for the common operation of creating timestamps for inserts and updates. We'll also dive into the Yii2 source code, examining how a behavior is implemented.


He starts with a brief look at what behaviors are (a reminder for those that may have already read about the sluggable and blameable behaviors). He then gets into the Timestamp behavior specifically and how to apply it to the sample project's "Status" instances. He shows the updates needed for the behavior configuration and rules. He also looks inside the component at the code that makes it up and the "touch" method it provides.


Link: http://code.tutsplus.com/tutorials/programming-with-yii2-timestamp-behavior--cms-23329

Nate Krantz: How I'm Writing Unit / Functional Tests


In a recent post Nate Krantz has shared some of his own methods around writing functional and unit tests.



So...testing. That thing that everyone says is so important but you don't really learn about it in school. I've had some trials and tribulations with testing so I'm going to just dump out some thoughts here.


He starts with a bit of background on his own experiences in development and how he finally decided that testing would "solve everything". He started with unit tests (for a CodeIgniter application) and how he got them up and running. He talks about issues he found around dependencies (and static methods) and how he made use of mocks to reduce some of the issues with dynamic loading, at least how CodeIgniter does it. Unfortunately, this didn't work out as planned so he fell back to a test database and create more effective and simpler functional tests. Code examples are sprinkled through out the post to show how he was trying to solve the problem at different points in the process.


Link: http://www.natekrantz.com/why-test-driven-development-rocks-sucks/

Disable Website Notification Prompts in Safari

safari-allow-notifications


Oh thank goodness.

2015年5月21日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

PMG Blog: Symfony from Scratch


In the latest post to the PMG blog Chris Davis shows us how to create a Symfony application from scratch, that is without using the Symfony Standard repository/skeleton application.



The end goal here is to have an application that will send a simple Hello World message. So we're going to cover the core framework stuff, but save things like templating, database access, ORMs, and forms for later. The goal here to see how to scaffold a Symfony app to better understand why symfony standard does what it does and where to deviate. We'll end up with an app that uses the Symfony 3 directory structure.


Starting with the smallest "composer.json" he can (just symfony/symfony) he walks through the creation of the application one step at a time:



  • The Application Kernel
  • Handling Web Requests
  • What's in a Bundle?
  • Stepping into Configuration
  • AppBundle
  • Hello, World


The end result is a simple page outputting a "Hello, World" message, but it gives you a good foundation to work from and understanding of the simplest pieces needed to make a Symfony application.


Link: https://www.pmg.com/blog/symfony-from-scratch/