Firebase Admin SDK for PHP

This Admin SDK makes it easy to interact with Google Firebase from PHP applications.

The source code can be found at https://github.com/kreait/firebase-php/

Note

If you are interested in using a client for end-user access (for example, in a Node.js desktop or IoT application), as opposed to admin access from a privileged environment (like a server), you should instead follow the instructions for setting up a Firebase client SDK.

<?php

require __DIR__.'/vendor/autoload.php';

$firebase = (new Firebase\Factory)
    ->withCredentials(__DIR__.'/google-service-account.json')
    ->withDatabaseUri('https://my-project.firebaseio.com')
    ->create();

$database = $firebase->getDatabase();

$newPost = $database
    ->getReference('blog/posts')
    ->push([
        'title' => 'Post title',
        'body' => 'This should probably be longer.'
    ]);

$newPost->getKey(); // => -KVr5eu8gcTv7_AHb-3-
$newPost->getUri(); // => https://my-project.firebaseio.com/blog/posts/-KVr5eu8gcTv7_AHb-3-

$newPost->getChild('title')->set('Changed post title');
$newPost->getValue(); // Fetches the data from the realtime database
$newPost->remove();