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시간 제공됩니다.

    연중무휴 24시간 전화 지원