承接 aliyunfc/fc-php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aliyunfc/fc-php-sdk

Composer 安装命令:

composer require aliyunfc/fc-php-sdk

包简介

Aliyun FC SDK for PHP

README 文档

README

Latest Stable Version Build Status Coverage Status

Overview

The SDK of this version is dependent on the third-party HTTP library guzzlehttp/guzzle.

Running environment

  • PHP 5.6+.
  • cURL extension.

Installation

The recommended way to install fc-php-sdk is through Composer.

$ composer require aliyunfc/fc-php-sdk

You can also declare the dependency on Alibaba Cloud FC SDK for PHP in the composer.json file.

 "require": {
      "aliyunfc/fc-php-sdk": "~1.2"
  }

Then run composer install --no-dev to install the dependency. After the Composer Dependency Manager is installed, import the dependency in your PHP code:

 require_once __DIR__ . '/vendor/autoload.php';

Getting started

<?php

require_once __DIR__ . '/vendor/autoload.php';
use AliyunFC\Client;

// To know the endpoint and access key id/secret info, please refer to:
// https://help.aliyun.com/document_detail/52984.html
$fcClient = new Client([
    "endpoint" => '<Your Endpoint>',
    "accessKeyID" =>'<Your AccessKeyID>',
    "accessKeySecret" =>'<Your AccessKeySecret>'
]);

// Create service.
$fcClient->createService('service_name');
 
/*
Create function.
the current directory has a main.zip file (main.php which has a function of my_handler)
set environment variables {'testKey': 'testValue'}
*/
$fcClient->createFunction(
    'service_name',
    array(
        'functionName' => $functionName,
        'handler' => 'index.handler',
        'runtime' => 'php7.2',
        'memorySize' => 128,
        'code' => array(
            'zipFile' => base64_encode(file_get_contents(__DIR__ . '/main.zip')),
        ),
       'description' => "test function",
       'environmentVariables' => ['testKey' => 'testValue'],
			)
		);

//Invoke function synchronously.
$fcClient->invokeFunction('service_name', 'function_name');

/*
Create function with initializer.
the current directory has a main.zip file (main.php which hava functions of my_handler and my_initializer)
set environment variables {'testKey': 'testValue'}
*/
$fcClient->createFunction(
    'service_name_with_initializer',
    array(
        'functionName' => $functionName,
        'handler' => 'index.handler',
        'initializer' => 'index.initializer',
        'runtime' => 'php7.2',
        'memorySize' => 128,
        'code' => array(
        'zipFile' => base64_encode(file_get_contents(__DIR__ . '/main.zip')),
        ),
        'description' => "test function with initializer",
        'environmentVariables' => ['testKey' => 'testValue'],
            )
         );

//Invoke function synchronously.
$fcClient->invokeFunction('service_name_with_initializer', 'function_name');

//Create trigger, for example: oss trigger
$prefix = 'pre';
$suffix = 'suf';
$triggerConfig = [
    'events' => ['oss:ObjectCreated:*'],
    'filter' => [
        'key' => [
            'prefix' => $prefix,
            'suffix' => $suffix,
        ],
    ],
];
$sourceArn = 'acs:oss:cn-shanghai:12345678:bucketName';
$invocationRole = 'acs:ram::12345678:role/aliyunosseventnotificationrole';
$ret = $fcClient->createTrigger(
    'service_name',
    'function_name',
    [
        'triggerName' => 'trigger_name',
        'triggerType' => 'oss',
        'invocationRole' => $invocationRole,
        'sourceArn' => $sourceArn,
        'triggerConfig' => $triggerConfig,
    ]
);


//Invoke a function with a input parameter.
$fcClient->invokeFunction('service_name', 'function_name', $payload='hello_world');

    
// Invoke function asynchronously.
$fcClient->invokeFunction('service_name', 'function_name', 'hello world', ['x-fc-invocation-type' => 'Async']);

// List services.
$fcClient->listServices();

//List functions with prefix and limit.
$fcClient->listFunctions('service_name', ['prefix' => 'hello', "limit" => 2]);

//List triggers
$fcClient->listTriggers('service_name', 'function_name');

//Delete trigger
$fcClient->deleteTrigger('service_name', 'function_name', 'trigger_name');
    
//Delete function
$fcClient->deleteFunction('service_name', 'function_name');
    
//Delete service.
$fcClient->deleteService('service_name');

Testing

To run the tests, please set the access key id/secret, endpoint as environment variables. Take the Linux system for example:

$ export ENDPOINT=<endpoint>
$ export ACCESS_KEY_ID=<AccessKeyId>
$ export ACCESS_KEY_SECRET=<AccessKeySecret>
$ export ACCOUNT_ID=<AccountId>
...

For details, refer to client_test.php

Run the test in the following method:

$ phpunit

More resources

Contacting us

License

aliyunfc/fc-php-sdk 适用场景与选型建议

aliyunfc/fc-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.73k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2018 年 09 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「aliyun」 「fc」 「fcunction compute」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 aliyunfc/fc-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aliyunfc/fc-php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 aliyunfc/fc-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 7
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-08