tencent cloud

フィードバック

Examples

最終更新日:2021-07-07 15:14:14

    These examples provide code snippets based on PHP 7.2 for your reference.

    You can click scf-php-code-snippet to obtain the relevant code snippets and directly use them for deployment.

    Obtaining Environment Variables

    This example shows you how to obtain all or a single environment variable.

    <?php
    function main_handler($event, $context) {
      print_r($_ENV);
      echo getenv('SCF_RUNTIME');
      return "hello world";
    }
    ?> 
    

    Formatting Local Time

    This example shows you how to output date and time in the specified format.

    The SCF environment uses the UTC format by default. To output in Beijing time, you can add the TZ=Asia/Shanghai environment variable to the function, and use date_default_timezone_set(getenv('TZ')); in the function code to set the needed time zone, as shown below:

    <?php
    function main_handler($event, $context) {
      date_default_timezone_set(getenv('TZ'));
      echo date("Y-m-d H:i:s",time()); 
      return "hello world";
    }
    ?> 
    

    Initiating Network Connections in a Function

    <?php
    function main_handler($event, $context) {
      $url = 'https://cloud.tencent.com';
      echo file_get_contents($url);
      return "hello world";
    }
    ?> 
    
    お問い合わせ

    カスタマーサービスをご提供できるため、ぜひお気軽にお問い合わせくださいませ。

    テクニカルサポート

    さらにサポートが必要な場合は、サポートチケットを送信して弊社サポートチームにお問い合わせください。24時間365日のサポートをご提供します。

    電話サポート(24 時間365日対応)