Version: current

     1 <?php
     2
     3 /**
     4  * This static publisher can be used to deploy static content to multiple hosts, by generating the cache files locally and then rsyncing then to
     5  * each destination box.  This can be used to set up a load-balanced collection of static servers.
     6  *
     7  * @see http://doc.silverstripe.com/doku.php?id=staticpublisher
     8  *
     9  * @package cms
    10  * @subpackage publishers
    11  */
    12 class RsyncMultiHostPublisher extends FilesystemPublisher {
    13     /**
    14      * Array of rsync targets to publish to.  These can either be local file names, or scp-style targets, in the form "user@server:path"
    15      */
    16     static $targets;
    17
    18     /**
    19      * Set the targets to publish to.
    20      * If target is an scp-style remote path, no password is accepted - we assume key-based authentication to be set up on the application server
    21      * initiating the publication.
    22      *
    23      * @param $targets An array of targets to publish to.  These can either be local file names, or scp-style targets, in the form "user@server:path"
    24      */
    25     static function set_targets($targets) {
    26         self::$targets = $targets;
    27     }
    28
    29     function publishPages($urls) {
    30         parent::publishPages($urls);
    31         $base = Director::baseFolder();
    32
    33         // Get variable that can turn off the rsync component of publication
    34         if(isset($_GET['norsync']) && $_GET['norsync']) return;
    35
    36         foreach(self::$targets as $target) {
    37             // Transfer non-PHP content from everything to the target; that will ensure that we have all the JS/CSS/etc
    38             $rsyncOutput = `cd $base; rsync -av -e ssh --exclude /.htaccess --exclude '*.php' --exclude '*.svn' --exclude '*~' --delete . $target`;
    39             // Then transfer "safe" PHP from the cache/ directory
    40             $rsyncOutput .= `cd $base; rsync -av -e ssh --exclude '*.svn' --exclude '*~' --delete cache $target`;
    41             if(StaticPublisher::echo_progress()) echo $rsyncOutput;
    42         }
    43     }
    44
    45 }
    46

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -