Posts

OpsWorks: Deploying your PHP Application Without Restarting Apache

Image
For quite a while now I have been trying to exploit AWS OpsWorks to deploy software updates to our MetaSearch Gateway with less manual work. Before using OpsWorks, I built AWS servers from custom AMI, deployed app using git push to remote, and remote deployment hook pulled latest code updates to a folder; and if there were any secondary servers, these were updated with rsync. Now, AWS OpsWorks is great set of tools, based on famous Chef (currently 11.4 is supported). With little efforts I was able to include and configure necessary PHP extensions to a default PHP Web app: APC memcached Mongo Geoip Since AWS supports also elastic load balancer, I have two 24/7 instances running behind ELB, and third server (load-based) waiting for load to increase. Deployments are quite easy, with a push of a button, code is pulled from remote git and symlinks are updated. Sounds good? Well, too good to be true. By default, after deploying your app, Apache restarts itself; and naturally this c...

MongoDB Backup Strategies with Write-Heavy Applications

Image
The MongoDB Management Service  Backup announced earlier in May provides excellent backup and restore capabilities for your MongoDB replica set cluster. Setting up MongoDB backup is quite easy: Sign Up for service, Provide credit card details Install and configure agent In ~ 10 minutes your replica set is backed up and backup agent starts transferring the oplog data to backup mothership. Price for snapshot creating and storage is negligible, compared to the price ($2/GB) for oplog processing. For example, previous invoice was $0.89 for 330GB Snapshot storage, $0.65 for 71GB for snapshot create and $155 for 77GB of oplog traffic.  After analyzing my application, I figured out that most of the traffic was caused by two collections: metalog - 1GB capped collection which stores every API request with details opcounters - this stores various opcounters; every minute new document is created and $inc operator increases various counter(s) by one, depending on action, ...

Make Your phpUnit Tests Run Faster by Sharing Fixtures

Image
There are few good reasons why you may want to share the fixtures between test, and most of the time the reason could be a bad design. For example, you would like to use share database connections, but your database adapter does not implement Singleton pattern . In order to take advantage of sharing fixtures between tests within single Test Case, your test case should implement two public static methods setUpBeforeClass() and tearDownAfterClass() , and shared fixture itself should be protected static variable. Following example shows sharing database fixture between tests: <?php class DatabaseTest extends PHPUnit_Framework_TestCase { protected static $dbh; public static function setUpBeforeClass() { self::$dbh = new PDO('sqlite::memory:'); } public static function tearDownAfterClass() { self::$dbh = NULL; } public function testShouldReturnCountGreaterThanZero() { $cmd = self::$dbh->prepare('SELEC...

10gen Announces Company Name Change to MongoDB, Inc.

Image
New York—August 27, 2013—10gen, the MongoDB company, today announced it is changing its name to MongoDB, Inc. The new name more closely unifies the open-source database project with the company behind it. The change is effective immediately. “In 2007, 10gen began work on an open-source cloud computing stack. That was the birth of MongoDB, as the data layer of that platform,” said Dwight Merriman, Chairman and Co-founder at 10gen. “When we saw the potential for the database we had built we decided to focus 100% on MongoDB. Thus the company name 10gen and the database name MongoDB were different. With this change, our goal is to get the names back into alignment.” The MongoDB project, and its mongodb.org community website, are unaffected by this change. 10gen will change its corporate website from 10gen.com to mongodb.com . As part of today’s announcement, 10gen Education, which provides free, online training as well as public and private in-person courses, has been rebranded MongoD...

Stubbing and Mocking Static Methods with PHPUnit

Image
PHPUnit has ability to stub and mock static methods. Consider the class Foo : <?php class Foo { public static function doSomething() { return static::helper(); } public static function helper() { return 'foo'; } } ?> To test the static helper() function with PHPUnit, you can write you test like that: <?php class FooTest extends PHPUnit_Framework_TestCase { public function testDoSomething() { $class = $this->getMockClass( 'Foo', /* name of class to mock */ array('helper') /* list of methods to mock */ ); $class::staticExpects($this->any()) ->method('helper') ->will($this->returnValue('bar')); $this->assertEquals( 'bar', $class::doSomething() ); } } ?> The new staticExpects() method works similar to the non-static expects...

Finding project files containing console.log()

Image
Found this little snippet online and modified for my own purposes. The goal was to find all template and PHP files containing console.log() operations, left in by other developers and programmers for debugging purposes. You don't want to have these files in your production environment, therefore before committing your code you could (with little modifications) add this to your pre-commit git hook and refuse commit if certain files contain console.log(). egrep -lir --include=*.{php,phtml,tpl} "(console\.log\()" . Following command will find all PHP, PHTML and TPL files in current folder which contain string  console.log( It will simply list all the files. You could pipe it with " | wc -l" to get counts.

View Manual Webspam Actions in Webmaster Tools

Image
From  Official Google Webmaster Central Blog: View manual webspam actions in Webmaster Tools : Webmaster level: All We strive to keep spam out of our users’ search results. This includes both improving our webspam algorithms as well as taking manual action for violations of Google's quality guidelines. In case you have noticed, there is new link under Search Traffic  called Manual Actions . If you click on it, and find message stating "No manual webspam actions found." then congrats, you have done everything right. A recent analysis of Google index showed that well under 2% of domains are manually removed for webspam. If you are one of the few unlucky who do have manual spam action, you probably have message in your inbox (and Google keeps sending these until you take appropriate actions). Here’s what it would look like if Google had taken manual action on a specific section of a site for "User-generated spam": According to Google, Once you’ve ...