Press "Enter" to skip to content

Tag: php

Running Jenkins CI for PHP on Amazon EC2 [2/7]

Continued from Part 1 – Introduction

Signing up to Amazon EC2 and starting your first image

  1. Sign up to Amazon’s AWS service at http://aws.amazon.com
  2. You will be prompted for payment details, but you won’t be charged if you use Amazon’s free Micro EC2 instance
  3. Wait for your account to be created – you will get an email once done, but it’ll take a few hours (it took me 3 hours)
  4. Log back into http://aws.amazon.com and select “Amazon EC2”
  5. Select the closest region to yourself in the left hand side
  6. Select “Launch instance” and, if prompted, select “Launch classic wizard”
  7. Select, from the Quck Start tab, the “Basic 64 Bit Amazon Linux AMI” image. This should be near the top and indicated with a big gold star to indicate “Free tier eligible if used with a micro instance”. Click continue
  8. Set the number of instances to 1 and the Instance type to “Micro”.
  9. Under “Launch instances”, select an EC2 availability zone or just leave it set to “No preference”. Click continue.
  10. Ignore the “Advanced instance options” and just click continue
  11. Ignore the Tags page and just click continue
  12. Select “Create a new Key Pair” and give it a name (such as AmazonInstance) and then “Create and download your key pair” and save the file some where important. Click continue.
  13. On the “Create a new security group”, create a name group called “JenkinsSSH” with a description of “Web and SSH access” and:
    • Create a new inbound rule with “Custom TCP rule”, port range “8080”, Source “0.0.0.0/0”. Click Add rule
    • Create a new inbound rule with “Custom TCP rule”, port range “22”, Source “0.0.0.0/0”. Click Add rule
    • Click “Launch” and wait a couple of minutes
    • Once it has launched, scroll down the bottom half of the “My Instances” panel until you see the “Public DNS” and make a record of that entry (ec1-23-456-78-901.xx-yyyy-1.compute.amazonaws.com)

Continued in Preparing PuTTY for Amazon EC2

Running Jenkins CI for PHP on Amazon EC2 [1/7]

Introduction
To ensure code quality for your PHP application, you might want to use a continuous integration service such as Jenkins CI (previously known as Hudson) to run things like PHPUnit, Code Coverage checks, PHP Mess Detector etc. But how do you install and run this cheaply? This series of 7 “easy to follow” tutorials will let you start and stop an Amazon EC2 “Micro” instance (which is free for your first year using Amazon) for testing.

These posts will be published on a daily basis between the 27th of October and 2nd of November inclusive.

  1. Signing up to Amazon EC2 and starting your first image
  2. Preparing PuTTY for Amazon EC2
  3. Connecting to Amazon EC2 using PuTTY
  4. Installing and Configuring Jenkins CI (this is the big/important post)
  5. Make a backup of the Amazon EC2 configuration
  6. Relaunching the Amazon EC2 image

PHP: Magento – current stock value

If you run the Magento ecommerce shopping cart software and you want to find out how much your stock is worth, how many product lines you have stocked and how many individual items you have, you may find the following MySQL query handy.

I’m assuming that you’ve created an attribute with the attribute code “supplier_price” as a decimal, that you’ve kept this field up to date and your stock levels are accurate 😀 If it isn’t called “supplier_price” change the appropriate part in the query.

SELECT
COUNT(sku) AS 'products_stocked',
SUM(qty) AS 'items_in_stock',
SUM(stockvalue) AS 'stock_value'
FROM (

SELECT
catalog_product_entity.sku,
cataloginventory_stock_item.qty,
catalog_product_entity_decimal.value,
(cataloginventory_stock_item.qty * catalog_product_entity_decimal.value) AS stockvalue
FROM
cataloginventory_stock_item,
catalog_product_entity,
eav_attribute,
catalog_product_entity_decimal
WHERE
catalog_product_entity.type_id='simple' AND
cataloginventory_stock_item.product_id=catalog_product_entity.entity_id AND
catalog_product_entity_decimal.entity_id=catalog_product_entity.entity_id AND
eav_attribute.attribute_id=catalog_product_entity_decimal.attribute_id AND
eav_attribute.attribute_code='supplier_price' AND
cataloginventory_stock_item.qty > 0
ORDER BY sku ASC) AS b

PHP Profilers – A Quick summary

More an aid to memory then anything, here’s the PHP profilers I’ve recently heard about:

XDebug by Derick Rethans
The oldest and most well known profiler. Needs modification of the server’s PHP file to run. Compatible with KCachegrind/WinCacheGrind, MacCallGrind and Webgrind and remote debugging tools. Produces quite large debug files (typically 900Kb to 10Mb compare to XHProf’s 110Kb).
XHProf by Facebook Inc (available via PECL)
Large amount of information provided and allows you to “drill down” by various sections – allows comparison of “diffs” between runs to check performance enhancements. Needs modification of the server’s PHP file to run. Also compatible with the *Grind systems. Used by Facebook and Manga High’s online maths games website, but only currently runs on Linux/FreeBSD. Seems to be preferred by iBuildings (see Profiling with XHProf) which is how I originally heard about it.
PHP Quick Profiler (PQP) by Particle tree
Needs modifications to your PHP code, but does not need the server’s PHP modifying (so it can be used on shared hosting easily). Nice and bright. Used by ParticleTree on their Wufoo product.

PHP: Getting individual packages on Zend Framework

@binarykitten (on Twitter) had the question I officially give up.. how the hell do you download only 1 component of the Zend Framework? I’ve been looking all over the site and I told her that I wasn’t aware of a method, that there were potential dependencies and to maybe try asking @calevans. He responded with the link http://epic.codeutopia.net/pack/ which appears to be a packager for the PHP Zend Framework versions 1.6 and 1.7 developed by Jani Hartikainen (@jhartikainen).

So, yes, it is possible to (unofficially) download parts of the Zend Framework and not have to worry about dependences.