Tag: symfony

Symfony bootstrap.php.cache failed to open stream: No such file or directory

When you get a message like (e.g. when clearing the cache):

PHP Warning:  require_once(/home/developer/my-project/bin/../var/bootstrap.php.cache): failed to open stream: No such file or directory in /home/developer/my-project/bin/console on line 10

Then the  bootstrap.php.cache file was not created for different reasons. Normally it should be generated after running “composer install” in your project directory.

If you need to generate it manually, just run the following command in your Symfony project folder:

php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php

If you have the new Symfony 3 folder structure you need to add three arguments:

php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php var app new

The file will then be generate in var/bootstrap.php.cache instead of app/bootstrap.php.cache.

Symfony 1.4: symfony generator Invalid column name ‘id’

It seems that the symfony generator needs a primary key. If there’s no PK defined the generator throws the following exception:

symfony generator Invalid column name ‘id’

In some blog post they solved the problem by adding a primary key to the concerning table. But in my case the DB isn’t under my control, so I found out that it is enough to set the primary key only in the schema.

For instance:

  connection: doctrine
  tableName: MyTable
      type: int(11)
      primary: true  # <-- SET TO true

Symfony 1.4: Doctrine: There is no open connection

When you have this problem just go into your controler e.g. index.php and add the following line:

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
new sfDatabaseManager($configuration);

Symfony: Instruct browser to refresh CSS and JS files

In Symfony the stylesheets and javascript files are defined in the view.yml. Sometimes the problem appears that the browsers cache these files, even if there where some changes in the last release without refreshing the new contents.

There is a common technique to instruct the browser to take the new file version: Browsers store different file versions for different GET paramters. So if you include a CSS file like this:

<script type="text/javascript" src="css/styles.css?v=21"></script>

and in the next version with a higher version number (v=22), the browser will use  (and cache) the newer version.

In our case we save the current version number (SVN) into the app.yml and we use this number as increasing GET-Parameter to force a cache refresh:

  stylesheets: [styles.css?v=<?php echo sfConfig::get('app_revision'); ?>]

Symfony cache folder on Windows Azure

I had the problem, that symfony had no write permissons to create the cache files in the Windows Azure approot folder.

After some research I found out, that it is possible to allocate local storage where the role user has write permissions. The disadvantage though is, that the local storage is not persistent, that means, it will be reset after role upgrades, instance reimage or reboots. But for caching I don’t need a persistent storage.

To get it running you need the folowing settings:


Define a local resource, in this case with the folder name “FileCacheStorage” and the size 1000MB:

<?xml version="1.0" encoding="UTF-8"?>
<ServiceDefinition name="MyWebRole" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole enableNativeCodeExecution="true" name="WebRole" vmsize="ExtraSmall">
      <LocalStorage name="FileCacheStorage" sizeInMB="1000" />


Change the default symfony cache path within the “setup()” method:

    if(strpos($_SERVER['HTTP_HOST'], "")===false)
    	$azureFileCachePath = substr($_SERVER['TEMP'], 0, 3).'Resources\Directory\\'.$_SERVER['RoleDeploymentID'].'.WebRole.FileCacheStorage\\cache';
    	$azureFileLogPath   = substr($_SERVER['TEMP'], 0, 3).'Resources\Directory\\'.$_SERVER['RoleDeploymentID'].'.WebRole.FileLogStorage\\log';

		  // Replace default path with local azure storage path, defined in ServiceDefinition ("LocalStorage" = "FileCacheStorage"):

Notice: When you are testing in your local dev environment the local storage path is completely different (more information here), so I decided to change the path only in the cloud env, because locally I have no write problems. To get the recent drive letter I take it from $_SERVER['TEMP'].

(For the symonfy logging I did it the same way.)

Special thanks to Taylor for his hints.

I hope this helps somebody ;)



Copyright © 2007-2012 iTopia. All rights reserved.
Jarrah theme by Templates Next | Powered by WordPress