使用Firebase和PHP脚本

I've always written my web services from scratch (PHP + MySQL). Firebase has caught my attention for its apparent ease of use and speed of development. Before I started integrating it into my app, I had already written some PHP scripts which query a public API and return the results to my app. I'm thinking it would be cool if I could use Firebase to cache these results by adding them to the NoSQL DB, but I'm not totally clear on how I would do this. Can I host my scripts somewhere in Firebase? If not, I guess I just grab one of the open source SDKs off Github, but it seems like hosting scripts outside of the service isn't the ideal workflow. Maybe there is a way to call an external API and parse the results with Firebase itself?

No, Firebase can't run your code, but what you have in mind is a perfectly legitimate workflow. You can move the bulk of your non-sensitive business logic to the front end, while running some secret sauce on a server.

The way to think of it is that your server is just another client to Firebase, it just has extra privileges and duties.

Read this blog post. Your use case sounds like Pattern 2: Firebase-powered app with server code, which they partly explain as:

In some cases it’s not possible to get away with only client code. Let’s look at a few examples:

  • You want your app to integrate with third party APIs (like Twilio to send an SMS, or SendGrid to send an email).

From Firebase website

We deliver all of your static content (html, js, images, etc.) over a secure SSL connection and serve it on a CDN.

Firebase Hosting is for hosting static assets

Answered here