Symfony, performance, and High CPU usage

Server is slowing down, and noticing that your Symfony project is consuming enormous amount of CPU? Try this tweak: # factories.yml all: routing: class: sfPatternRouting param: cache: null **What it does:** This config disables the Symfony Routing Cache, which uses PHP serialize/unserialize functions, and can cause lots of CPU processing. In my case, a high server load of ~8 went under 1 with this simple tweak (on a dual core). Easy change, but hard to find in the docs.
Read more...

Symfony directory’ variables

For the times you’ll need access to some of Symfony’s directories: Symfony dir [php] // root directory structure 'sf_cache_dir_name' = 'cache', 'sf_log_dir_name' = 'log', 'sf_lib_dir_name' = 'lib', 'sf_model_dir_name' = 'model', 'sf_web_dir_name' = 'web', 'sf_data_dir_name' = 'data', 'sf_config_dir_name' = 'config', 'sf_apps_dir_name' = 'apps', // global directory structure 'sf_app_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$sf_app, 'sf_model_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'model', 'sf_lib_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'lib', 'sf_web_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'web', 'sf_upload_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR.'uploads', 'sf_base_cache_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.$sf_app, 'sf_cache_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.$sf_app.DIRECTORY_SEPARATOR.$sf_environment, 'sf_log_dir' = $sf_root_dir.DIRECTORY_SEPARATOR.'log', 'sf_data_dir' = $sf_root_dir.
Read more...

Retrieve custom columns in Symfony

Sometimes while retrieving data, you might not need all the columns, especially on a large database query result set.

Symfony, or actually Propel (1.3) allows you to chose what columns to retrieve, and skip the hydrate process:

// Custom column, on large subset
$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(TitlePeer::ID);
$c->addSelectColumn(TitlePeer::TITLE);
$resTitleRS = TitlePeer::doSelectStmt($c);
// Loop through result and create custom array
while ($row = $resTitleRS->fetch(PDO::FETCH_ASSOC)) {
  $title_id = $row['ID'];
  $title_name = $row['TITLE'];
  $arrTitleDB[$title_id] = $title_name;
}

Symfony rollout process with rsync

Symfony has a build-in rsync command line, which makes it easy to rollout your code into production. You can define multiple connections, in case you have multiple servers, a load balancer, backups… In project/config/properties.ini: [symfony] name=codingfolder [production1] host=myapp.example.com port=22 user=myuser dir=/home/myaccount/myproject/ [production2] host=myapp.example.com port=22 user=myuser dir=/home/myaccount/myproject/ Then, from the root directory of your project:
Read more...