Support

Find answers, guides, and tutorials to supercharge your content delivery.

Phalcon CDN Integration

Updated on January 6, 2023

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:

    <?php
    
    $url = new Phalcon\Mvc\Url();
    
    // Dynamic URIs remain on your origin server
    $url->setBaseUri('/');
    
    // Static resources go through KeyCDN
    $url->setStaticBaseUri('http://cdn.foobar.com/');
    
  3. Alternative: Use collections and add a URL-prefix for your CDN URL.

    <?php
    
    $css = $this->assets->collection('header');
    $scripts = $this->assets->collection('footer');
    
    if ($config->environment == 'development') {
        $css->setPrefix('/');
        $scripts->setPrefix('/');
    } else {
        $cdnURL = 'http://example-hexid.kxcdn.com/';
        $css->setPrefix($cdnURL);
        $scripts->setPrefix($cdnURL);
    }
    
    $css->addCss('css/bootstrap.min.css')
            ->addCss('js/custom.css');
    
    $scripts->addJs('js/jquery.js')
            ->addJs('js/bootstrap.min.js');
    
  4. Alternative: In case you don't want to use collections, use this approach:

    ...
    $cdnURL = 'http://example-hexid.kxcdn.com/';
    $this->assets
         ->addCss($cdnURL.'css/custom.css', false);
    ...
    
  5. As always, verify the HTML source code if the assets are pointing to your CDN URL.

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more