Speedup Symfony2 with APC

Posted on 24 December 2011.

First you need to install APC, and (if you want) igbinary.

Change apc.shm_size to 64M at least, if you have installed igbinary switch apc.serializer to igbinary.


Your autoload.php :

<?php
require __DIR__.'/../vendor/symfony/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';

use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = new ApcUniversalClassLoader('sf2.apc.');
For more APC informations into Symfony2 you can install the ApcProfilerBundle.

Install PHP 5.3.7 on OS X Lion

Posted on 18 August 2011.

First you need to install libjpeg, libpng and download/extract the Suhosin path


Install command :

export MACOSX_DEPLOYMENT_TARGET=10.7
export CFLAGS="-arch x86_64"
export CXXFLAGS="-arch x86_64"

cd php-5.3.7
patch -p 1 -i ../suhosin-patch-5.3.7-0.9.10.patch

./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/private/etc --with-apxs2=/usr/sbin/apxs --enable-cli --with-config-file-path=/etc --with-libxml-dir=/usr --with-openssl=/usr --with-kerberos=/usr --with-zlib=/usr --enable-bcmath --with-bz2=/usr --enable-calendar --with-curl=/usr --enable-dba --enable-exif --enable-ftp --with-gd --with-freetype-dir=/Developer/SDKs/MacOSX10.7.sdk/usr/X11 --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --enable-gd-native-ttf --with-iodbc=/usr --with-ldap=/usr --with-ldap-sasl=/usr --with-libedit=/usr --enable-mbstring --enable-mbregex --with-mysql=mysqlnd --with-mysqli=mysqlnd --without-pear --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/mysql/mysql.sock --with-readline=/usr --enable-shmop --with-snmp=/usr --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-wddx --with-xmlrpc --with-iconv-dir=/usr --with-xsl=/usr --enable-zend-multibyte --enable-zip --with-pcre-regex --with-pgsql=/usr --with-pdo-pgsql=/usr
make
sudo make install

If you want to install Intl

First install ICU 4.6, add --enable-intl in ./configure, open Makefile and add -lstdc++ to EXTRA_LIBS

Fetching groups with PDO

Posted on 17 August 2011.

PDO offers a very usefull option in it's fetchMode : PDO::FETCH_GROUP which allows you to group entries by category.


Table Exemple:

test_user :
+----+-----------+----------+-------+
| id | firstname | lastname | city  |
+----+-----------+----------+-------+
|  1 | Jean      | Machin   | Paris |
|  2 | Jean      | Truc     | Nice  |
|  3 | Paul      | Bla      | Nice  |
+----+-----------+----------+-------+
<?php
$result = $pdo->query("SELECT u.city, u.id, u.firstname, u.lastname FROM test_user u")
              ->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP);
?>

Result (in YAML) :

Paris:
    - { id: 1, firstname: Jean, lastname: Machin }
Nice:
    - { id: 2, firstname: Jean, lastname: Truc }
    - { id: 3, firstname: Paul, lastname: Bla }

With another query :

SELECT u.firstname, u.id, u.lastname, u.city FROM test_user u
Jean:
    - { id: 1, lastname: Machin, city: Paris }
    - { id: 2, lastname: Truc, city: Nice }
Paul:    
    - { id: 3, lastname: Bla, city: Nice }