Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine error: "Failed opening required '/tmp/__CG__Source.php' "

I am trying to migrate my PHP application to an Ubuntu server, but without succes. Any help would be appreciated.

First I installed Doctrine successfully into /jorrit/myapp, following the first part of Doctrine's Getting Started manual (till "Generating the Database Schema"). Secondly I placed my PHP scripts (which use Doctrine) in folder /jorrit/myapp.

When I try to run my PHP script in the CLI, I get this error messages:

PHP Warning: require(/tmp/__CG__Source.php): failed to open stream: No such file or directory in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200

PHP Fatal error: require(): Failed opening required '/tmp/__CG__Source.php' (include_path='.:/usr/share/php:/usr/share/pear') in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200

Bootstrap.php looks like this:

<?php // bootstrap.php use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager;  require_once "vendor/autoload.php";  // Create a simple "default" Doctrine ORM configuration for Annotations $isDevMode = false; $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);  // the connection configuration $dbParams = array(         'driver'   => 'pdo_mysql',         'host'     => 'xx',         'user'     => 'xx',         'password' => 'xx',         'dbname'   => 'xx',         'profiler' => 'false' );   // obtaining the entity manager $entityManager = EntityManager::create($dbParams, $config);  ?> 

The first lines of my PHP script:

<?php  require_once "bootstrap.php"; require_once 'classes.php';  $connection = $entityManager->getConnection(); 

The application works fine in my development environment (Windows). The /tmp folder exists and is accessible. The database is migrated succesfully and exists. I did not change anything in the vendor folder.

Any ideas? Thanks in advance for your help.

like image 565
Jorr.it Avatar asked Sep 28 '13 10:09

Jorr.it


2 Answers

TL;DR You'll just need to generate your proxy classes manually

vendor/bin/doctrine orm:generate-proxies 

Doctrine uses Proxies to connect the to database. Proxies are generated from the the Entity classes.

In development mode, it generates a Proxies on every request because you could make changes to Entity classes.

In production mode, it does not generate Proxies every time. For performance reason, it assumes the Proxies exist and include them directly.

There are a few mode for Proxies generation:

  1. ALWAYS - It alwayes generates Proxies, this is the default setting for development mode
  2. NEVER - It never generates Proxies, this is the default setting for production mode
  3. ON_DEMAND - It only generates the Proxies if the Proxy files do not exist. The drawback of this option is that it has to call file_exists() every time which could potentially cause a performance issue.

Now the command

vendor/bin/doctrine orm:generate-proxies 

generates Proxy classes to /tmp. I would say this might still cause trouble because other applications on your server might delete these files unexpectedlly. One option is you can change your /tmp directory access permission to 1777

sudo chmod 1777 /tmp 

The stricky bit '1' in front of 777 means that, although everyone can read/write to the /tmp directory, but you can only operate on your own files. i.e. You can't remove files created by other users.

For further reading, please have a look at http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#auto-generating-proxy-classes-optional

You can also set the Proxies directory to somewhere else so no other applications can modify them. http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#autoloading-proxies

like image 92
Zorji Avatar answered Sep 28 '22 11:09

Zorji


In code after $config line you could try $config->setAutoGenerateProxyClasses(true);

But the CLI version is much better, because it avoids on refresh regen as in code might not avoid.

To change cache dir you could try:

$cacheDir = dirname(__FILE__).'/cache'; if (!is_dir($cacheDir)) {     mkdir($cacheDir); }   $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $cacheDir); 
like image 29
michalzuber Avatar answered Sep 28 '22 11:09

michalzuber