Thu

17

May

2012

Memory and Doctrine 1.2

When dealing with doctrine 1.2 and medium data, you will probably see something like this:

 

Fatal error: Allowed memory size of X bytes exhausted (tried to allocate X bytes)

 

To avoid this you should care about the following points:

 

1. If you only want to read data fetch it as an array. Nobody needs an overloaded active record while read only.

 

$q->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY)

 

2. Select only the data you need - especially when using multiple inner joins.

 

$q->select('u.id, u.email, u.slug')
$q->from('User u')

 

3. Use pagination while using active records

 

4. Use free on objects you dont need any longer when using php <= 5.2.5

 

read more 0 Comments

Wed

09

May

2012

When good music hits tv series

When i watch some good tv-series, i very often get introduced into good music like this one. Thanks to Walking Dead and YouTube which introduced me into this one.

Enjoy Wye Oak with her incredible song called Civilian

read more 0 Comments

Wed

02

May

2012

Music feels like summer

read more 0 Comments

Sun

29

Apr

2012

Pimp your desktop with awesome wallpapers


read more 0 Comments

Thu

26

Apr

2012

Stop motion video explaining the order procedure of vTiger CRM

read more 0 Comments

Wed

25

Apr

2012

Speed up Swiftmailer while using an external smtp

Do you send lots of emails with one task via swiftmailer and an external smtp? Here are some tips for you:

 

1. One mailer object only!

Create the mailer object once and use this object for all the emails. Every time you create and use a new mailer object, a new smtp connection will be established. This would cost lots of time.

 

2. Use the anti flood plugin

We dont want to send all 9999999 emails via one smtp connection. If there is an error in the connection, it will be very bad for the emails followed. Instead of this, we will close the connection after x emails and create a new one. Thanks to Fabien Potencier, there is already a plugin thats doing this job called Swift_Plugins_AntiFloodPlugin. The following code will register theplugin which reestablishes connection after 200 mails:

$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(200));

 

3. Use caching in memory

Especially when you use the decorator plugin you should use the memory to cache the body.

 

For example:

Swift_Preferences::getInstance()
      ->setCacheType('disk')
      ->setTempDir('/run/shm')
;

 

4. Update swiftmailer

There was an error in the qp encoding of swiftmailer. Upgrade to the newest version will fix this. If you cannot upgrade for example with symfony 1.4, you can try to set the encoding to 8 bit. 

$message->setEncoder(Swift_Encoding::get8BitEncoding()); 
read more 0 Comments

Tue

24

Apr

2012

Awesome german music video by Thees Uhlmann

read more 0 Comments

Mon

23

Apr

2012

Syntax highlighting to html

Ever wanted to publish highlighted code online? Try this online syntax highlighter.

 

Support for a lot of languages and fancy themes and an api!

 

Link

read more 0 Comments

Sun

22

Apr

2012

Full page caching with Symfony2 and the Symfony2 reverse proxy

Activate the cache in web/app.php

require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
require_once __DIR__.'/../app/AppCache.php';

use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel = new AppCache($kernel);
$kernel->handle(Request::createFromGlobals())->send();

After that, go to your controller action. At first, you will need to create a new Response object. After that set it as public so the cached response is used by all visitors. Then you will need an unique identifier, the etag, for the cache - an id and a modified date of the resource for example. If the resource is not modified the cached response will be responded. If the resource was modified since the last cache got created, a new cached response will be created with the new eTag. See the example:

public function detailAction($id) {

        $response = new Response();
        $response->setPublic();

        $em = $this->get('doctrine')->getEntityManager();
 
        $article = //get article by id from repository
  
        $identifier = md5(
                        $article->getId().
                        $article->getUpdatedAt()->format('Y-m-d H:i:s')
                      )

        $response->setETag($identifier );

        if ($response->isNotModified($this->get('request'))) {
            return $response;
        }

        //do the heavy work 

        return $this->render(
            'MyAwesomeBundle:Board:detail.html.twig',
            array('awesomeObject' => $awesomeObject),
            $response
        );
    }
?>

Important: The Symfony2 reverse proxy is cool - but not that fast as reverse proxies written in c. If you want to build a website with a very high load, please consider using Varnish with Symfony2 for example.

read more 0 Comments

Sat

21

Apr

2012

Nice shoes of a bridesmaid

read more 0 Comments