تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
Cloud Functions لمنصة Firebase
plat_ios
plat_android
plat_web
plat_flutter
plat_cpp
plat_unity
Cloud Functions for Firebase هو إطار عمل بدون خادم يتيح لك تشغيل رمز الخلفية تلقائيًا استجابةً للأحداث التي يتم تشغيلها من خلال أحداث الخلفية أو طلبات HTTPS أو مهام
Admin SDK أو
Cloud Scheduler. يتم تخزين رمز JavaScript أو TypeScript أو Python على بنية Google Cloud الأساسية ويتم تنفيذه في بيئة مُدارة. ولن تحتاج إلى إدارة خوادمك وتوسيع نطاقها.
هل تستخدم Cloud Functions في Google Cloud؟
مزيد من المعلومات حول دور Firebase.
البدء
حالات الاستخدام
الإمكانات الرئيسية
تدمج ميزات Firebase وتربطها بخدمة Google Cloud |
يمكن أن تستجيب الدوال التي تكتبها للأحداث التي تنشئها ميزات مختلفة من Firebase وGoogle Cloud، بدءًا من مشغّلات Firebase Authentication إلى مشغّلات Cloud Storage.
يمكنك الدمج بين ميزات Firebase باستخدام
Admin SDK
مع Cloud Functions، والدمج مع خدمات تابعة لجهات خارجية
من خلال كتابة خطافات الويب الخاصة بك.
تساعد Cloud Functions في الحدّ من التعليمات البرمجية النموذجية، ما يسهّل استخدام Firebase وGoogle Cloud داخل الدالة. |
لا يحتاج إلى صيانة |
يمكنك نشر رموز JavaScript أو TypeScript أو Python البرمجية على خوادمنا باستخدام أمر واحد من سطر الأوامر.
بعد ذلك، تعمل Firebase تلقائيًا على زيادة موارد الحوسبة لتتطابق مع أنماط استخدام المستخدمين. لن تقلق بشأن بيانات الاعتماد أو إعداد الخادم أو توفير خوادم جديدة أو إيقاف الخوادم القديمة. |
الحفاظ على خصوصية منطقك وأمانه |
في كثير من الحالات، يفضّل المطوّرون التحكّم في منطق التطبيق على الخادم لتجنُّب التلاعب به من جهة العميل. بالإضافة إلى ذلك، قد لا يكون من المستحسن السماح بإجراء هندسة عكسية لهذا الرمز.
Cloud Functions معزول تمامًا عن العميل، لذا يمكنك التأكّد من أنّه خاص وينفّذ دائمًا ما تريده بالضبط. |
كيف تعمل هذه الميزة؟
بعد كتابة دالة ونشرها، تبدأ خوادم Google في إدارة الدالة على الفور. يمكن تشغيل الدالة مباشرةً باستخدام طلب HTTP أو Admin SDK أو مهمة مجدوَلة، أو في حالة الدوال التي تعمل في الخلفية، تستمع خوادم Google إلى الأحداث وتشغّل الدالة عند تفعيلها.
مع زيادة أو انخفاض الحمل، تستجيب Google من خلال توسيع نطاق عدد مثيلات الخادم الافتراضي المطلوبة لتشغيل وظيفتك بسرعة. يتم تشغيل كل دالة بشكل منفصل في بيئتها الخاصة مع إعداداتها الخاصة.
مراحل نشاط دالة تعمل في الخلفية
- تكتب رمزًا لدالة جديدة، وتختار موفّر أحداث (مثل
Cloud Firestore)، وتحدّد الشروط التي يجب أن يتم بموجبها تنفيذ الدالة.
- عند نشر الدالة:
- تنشئ واجهة سطر الأوامر (CLI) في Firebase أرشيفًا
.zip
لرمز الدالة،
يتم تحميله بعد ذلك إلى حزمة Cloud Storage (يسبقه
gcf-sources
) قبل أن تنشئ Cloud Functions مستودع Artifact Registry (اسمه
gcf-artifacts
) في مشروعك.
- يسترد Cloud Build رمز الدالة وينشئ مصدر الدالة. يمكنك عرض سجلّات Cloud Build في
وحدة تحكّم Google Cloud.
- يتم تحميل صورة الحاوية لرمز الدوال الذي تم إنشاؤه إلى مستودع Artifact Registry خاص في مشروعك (يُسمى
gcf-artifacts
)، ويتم طرح الدالة الجديدة.
- عندما ينشئ موفّر الأحداث حدثًا يتطابق مع شروط الدالة، يتم استدعاء الرمز. تتضمّن الدالة حساب خدمة مرفقًا بها يمكن استخدامه للوصول إلى خدمات Firebase الأخرى بمساعدة Firebase Admin SDK.
- إذا كانت الدالة مشغولة بمعالجة العديد من الأحداث، تنشئ Google المزيد من المثيلات
للتعامل مع العمل بشكل أسرع. إذا كانت الدالة غير نشطة، يتم تنظيف المثيلات.
- عند تعديل الدالة من خلال نشر رمز معدَّل، يتم تنظيف مثيلات الإصدارات القديمة مع عناصر البناء في Artifact Registry، واستبدالها بمثيلات جديدة.
- عند حذف الدالة، يتم تنظيف جميع مثيلاتها وأرشيفات zip، بالإضافة إلى عناصر البناء ذات الصلة في Artifact Registry.
تتم إزالة الربط بين الدالة ومقدّم الحدث.
بالإضافة إلى الاستماع إلى الأحداث باستخدام دالة تعمل في الخلفية، يمكنك استدعاء الدوال مباشرةً باستخدام طلب HTTP أو استدعاء من العميل. يمكنك أيضًا تشغيل الدوال
وفق جدول زمني ثابت أو
إضافة دوال المهام إلى قائمة الانتظار من خلال Admin SDK.
مسار التنفيذ
|
إعداد Cloud Functions |
ثبِّت واجهة سطر الأوامر Firebase وأعِد ضبطها
Cloud Functions في مشروعك على Firebase. |
|
كتابة الدوال |
كتابة رمز JavaScript أو رمز TypeScript أو رمز Python للتعامل مع الأحداث من خدمات Firebase أو خدمات Google Cloud أو مقدّمي الأحداث الآخرين |
|
دوال الاختبار |
استخدِم المحاكي المحلي
لاختبار الدوال. |
|
التفعيل والمراقبة |
يمكنك ترقية مشروعك إلى خطة أسعار Blaze بنظام الدفع حسب الاستخدام ونشر الدوال باستخدام واجهة سطر الأوامر Firebase. يمكنك بعد ذلك استخدام
وحدة تحكّم Google Cloud
للاطّلاع على سجلّاتك والبحث فيها. |
الخطوات التالية
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-17 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-17 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["Cloud Functions for Firebase \nplat_ios plat_android plat_web plat_flutter plat_cpp plat_unity \nCloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by background events, HTTPS requests, the Admin SDK, or Cloud Scheduler jobs. Your JavaScript, TypeScript or Python code is stored on Google Cloud infrastructure and runs in a managed environment. There's no need to manage and scale your own servers.\n\n\u003cbr /\u003e\n\nAlready using Cloud Functions in Google Cloud?\n[Learn more](/docs/functions/functions-and-firebase) about how Firebase fits\ninto the picture.\n\n[Get started](/docs/functions/get-started)\n[Use cases](/docs/functions/use-cases)\n\nKey capabilities\n\n|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Integrates Firebase features and connects Firebase with Google Cloud | The functions you write can respond to events generated by various Firebase and Google Cloud features, from [Firebase Authentication triggers](/docs/functions/auth-events) to [Cloud Storage Triggers](/docs/functions/gcp-storage-events). Integrate across Firebase features using the [Admin SDK](/docs/admin/setup) together with Cloud Functions, and integrate with third-party services by writing your own webhooks. Cloud Functions minimizes boilerplate code, making it easier to use Firebase and Google Cloud inside your function. |\n| Zero maintenance | Deploy your JavaScript, TypeScript, or Python code to our servers with one command from the command line. After that, Firebase automatically scales up computing resources to match the usage patterns of your users. You never worry about credentials, server configuration, provisioning new servers, or decommissioning old ones. |\n| Keeps your logic private and secure | In many cases, developers prefer to control application logic on the server to avoid tampering on the client side. Also, sometimes it's not desirable to allow that code to be reverse engineered. Cloud Functions is fully insulated from the client, so you can be sure it is private and always does exactly what you want. |\n\nHow does it work?\n\nAfter you write and deploy a function, Google's servers begin to manage the\nfunction immediately. You can fire the function directly with an HTTP request,\nthe Admin SDK, or a scheduled job, or, in the case of background functions,\nGoogle's servers listen for events and run the function when it is\ntriggered.\n\nAs the load increases or\ndecreases, Google responds by rapidly scaling the number of virtual server\ninstances needed to run your function. Each function runs in isolation, in its\nown environment with its own configuration.\n\nLifecycle of a background function\n\n1. You write code for a new function, selecting an event provider (such as Cloud Firestore), and defining the conditions under which the function should execute.\n2. When you deploy your function:\n 1. The Firebase CLI creates a `.zip` archive of the function code, which is then uploaded to a Cloud Storage bucket (prefixed with `gcf-sources`) before Cloud Functions creates an Artifact Registry repository (named `gcf-artifacts`) in your project.\n 2. Cloud Build retrieves the function code and builds the function source. You can view Cloud Build logs in the [Google Cloud console](//console.cloud.google.com/logs/query;query%3Dresource.type%253D%2522build%2522&sa=D&ust=1597179510979000&usg=AFQjCNG2BmFrgWjGoP83WiMrB2TLLXpBEQ).\n 3. The container image for the built functions code is uploaded to a private Artifact Registry repository in your project (named `gcf-artifacts`), and your new function is rolled out.\n3. When the event provider generates an event that matches the function's conditions, the code is invoked. The function has a service account attached to it that can be used to access other Firebase services with the help of the Firebase Admin SDK.\n4. If the function is busy handling many events, Google creates more instances to handle work faster. If the function is idle, instances are cleaned up.\n5. When you update the function by deploying updated code, instances for older versions are cleaned up along with build artifacts in Artifact Registry, and replaced by new instances.\n6. When you delete the function, all instances and zip archives are cleaned up, along with related build artifacts in Artifact Registry. The connection between the function and the event provider is removed.\n\nIn addition to listening for events with a background function, you can call\nfunctions directly with an HTTP request or a\n[call from the client](/docs/functions/callable). You can also trigger functions\non a fixed [schedule](/docs/functions/schedule-functions) or\n[enqueue task functions](/docs/functions/task-functions) via the Admin SDK.\n\nImplementation path\n\n|---|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| | Set up Cloud Functions | Install the Firebase CLI and initialize Cloud Functions in your Firebase project. |\n| | Write functions | Write JavaScript code, TypeScript code, or Python code to handle events from Firebase services, Google Cloud services, or other event providers. |\n| | Test functions | Use the [local emulator](/docs/functions/local-emulator) to test your functions. |\n| | Deploy and monitor | Upgrade your project to the [pay-as-you-go Blaze pricing plan](/pricing) and deploy your functions using the Firebase CLI. You can then use the [Google Cloud console](//console.cloud.google.com/functions/list) to view and search through your logs. |\n\nNext steps\n\n- [Get started](/docs/functions/get-started) setting up, creating, and deploying functions.\n- Learn more about [what you can do with functions](/docs/functions/use-cases).\n- Try the [Cloud Functions codelab](https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#0)."]]