Firebase Admin SDK for PHP
Interact with Google Firebase from your PHP application.
If you are interested in using the PHP Admin SDK as a client for end-user access (for example, in a web application), as opposed to admin access from a privileged environment (like a server), you should instead follow the instructions for setting up the client JavaScript SDK.
Documentation
You can find the full documentation at firebase-php.readthedocs.io.
Feature matrix
Feature | PHP | Node.js | Java | Python | Go |
---|---|---|---|---|---|
Custom Token Minting | ✅ | ✅ | ✅ | ✅ | ✅ |
ID Token Verification | ✅ | ✅ | ✅ | ✅ | ✅ |
Realtime Database API | ✅* | ✅ | ✅ | ✅* | ✅ |
User Management API | ✅ | ✅ | ✅ | ✅ | ✅ |
Cloud Messaging API | ✅ | ✅ | ✅ | ✅ | |
Cloud Storage API | ✅ | ✅ | ✅ | ✅ | |
Cloud Firestore API | ✅ | ✅ | ✅ | ✅ |
Note: The Realtime Database API in PHP/Python Admin SDK currently does not support realtime event listeners. This means there is no provision for adding event listeners to a database reference in order to automatically receive realtime update notifications. Instead, in PHP/Python updates should be proactively fetched by explicitly invoking read operations.
Usage example
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
// The following line is optional if the project id in your credentials file
// is identical to the subdomain of your Firebase project. If you need it,
// make sure to replace the URL with the URL of your project.
->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();
Support
For errors and missing features, please use the issue tracker.
For general support, join the #php
channel at https://firebase.community/.