Phalcon CDN Integration

This documentation guides you through the integration of KeyCDN with the high performance PHP framework Phalcon. There are different approaches to integrate KeyCDN, either use the base URI option, the asset management or simply a view helper which can produce all CDN URLs for your assets.

  1. Create a pull zone before you start the Phalcon CDN integration.
  2. The simplest but most generic approach is to define the setStaticBaseUri.
    $url = new Phalcon\Mvc\Url();
    // Dynamic URIs remain on your origin server
    // Static resources go through KeyCDN
  3. Alternative: Use collections and add a URL-prefix for your CDN URL.
    $css = $this->assets->collection('header');
    $scripts = $this->assets->collection('footer');
    if ($config->environment == 'development') {
    } else {
        $cdnURL = '';
  4. Alternative: In case you don’t want to use collections, use this approach:
    $cdnURL = '';        
         ->addCss($cdnURL.'css/custom.css', false);
  5. As always, verify the HTML source code if the assets are pointing to your CDN URL.

Relevant Links

Phalcon Asset Management
Phalcon View Helpers
Phalcon Generating URLs and Paths

Leave A Comment?