How can I access configuration variables from PHP?

When you deploy a Rails application, Scalarium generates the file database.yml, as that is the convention Rails uses to configure an application's database. Unfortunately, there is no such convention for PHP applications.

One way to access the database in a PHP app running on Scalarium is to create a custom Chef recipe that extracts the necessary bits from the node object and writes these into a PHP file that you then include in your app.

As accessing the database is something very common, there is now a simpler way to do so. When deploying a PHP application, Scalarium now generates the file scalarium.php and puts a link to that file right in your application's root directory.

Here's what you could put into your wp-config.php to get Wordpress running on Scalarium.

include_once('scalarium.php');
$scalarium = new Scalarium();

define('DB_NAME', $scalarium->db->database);
define('DB_USER', $scalarium->db->username);
define('DB_PASSWORD', $scalarium->db->password);
define('DB_HOST', $scalarium->db->host);

The configuration for memcached is available as well, using $scalarium->memcached instead of $scalarium->db.

There are two more things you can do with this helper right now. As stated in another knowledge base article, it is a pretty common task to find out the IP addresses of other instances of your cluster. The following snippet explains how to do that using scalarium.php.

include_once('scalarium.php');
$scalarium = new Scalarium();

foreach ($scalarium->roles() as $role) {
  $hosts = $scalarium->hosts($role);
  if ($hosts) {
    print "$role has the running instances " . implode(', ', $scalarium->hosts($role)) . "\n";
  } else {
    echo "$role has no running instances\n";
  }
}

$scalarium->roles() returns an array of short names of roles in your cluster. These are the names you can pass to $scalarium->hosts($role), which returns an array of IP addresses.