2

I know there is a PHP library that implement REST API: https://github.com/ktamas77/firebase-php

How do I listen to data changes on Firebase Database using PHP?

Since I need a long running PHP script that listens to data changes on specific nodes in Firebase Database. The PHP script will process the data changes and update to Firebase Database after processing.

AL.
  • 36,815
  • 10
  • 142
  • 281
Plugie
  • 1,289
  • 17
  • 25

1 Answers1

0

I recommended to use firebase trigger (functions) for your request, you can Create and Deploy Your Cloud Functions.

Firebase Trigger: https://firebase.google.com/docs/functions/write-firebase-functions

Node js request: https://www.npmjs.com/package/request

For example:

const functions = require('firebase-functions');
const request = require('request');

exports.setWriteServiceStatus = functions.database.ref('/').onWrite(event => {

    // API Url : http://www.amirhome.com
    request('http://www.amirhome.com', function (error, response, body) {
        console.log('error:', error); // Print the error if one occurred 
        console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received 
        console.log('body:', body); // Print the HTML for the Google homepage. 
    });

});

Note: If you wanted to call a third party web service (for example) you'd need to enable billing.

Cloud Functions for Firebase - Billing account not configured

Amir Hosseinzadeh
  • 7,360
  • 4
  • 18
  • 33