定制 dmamontov/asynctask-7 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dmamontov/asynctask-7

最新稳定版本:2.0.13

Composer 安装命令:

composer require dmamontov/asynctask-7

包简介

AsyncTask enables proper and easy use of the thread. This class allows to perform background operations and publish results on the thread without having to manipulate threads and/or handlers.

README 文档

README

Build Status Latest Stable Version License Total Downloads PHP Classes

AsyncTask

AsyncTask enables proper and easy use of the thread. This class allows to perform background operations and publish results on the thread without having to manipulate threads and/or handlers.

The early class implementation supports PHP 5.3, but does not support what is implemented in this class.

Requirements

  • PHP version ~7.1.0

  • Module installed pcntl and posix

  • All functions pcntl, posix removed from the directive disable_functions

  • SharedMemoryAdapter:

    • All functions shm removed from the directive disable_functions

Installation

  1. Install composer

  2. Follow in the project folder:

composer require dmamontov/asynctask-7 ~2.0.13

In config composer.json your project will be added to the library dmamontov/asynctask-7, who settled in the folder vendor/. In the absence of a config file or folder with vendors they will be created.

If before your project is not used composer, connect the startup file vendors. To do this, enter the code in the project:

require 'path/to/vendor/autoload.php';

Adapter list

  • SharedMemory - working
  • FileSystem - in the process
  • Redis - in the process

Offer adapters that are missing. We develop!

Examples

Example of work

use AsyncTask\{
    AsyncTask,
    Collection
};

class TestTask extends AsyncTask
{
    protected function onPreExecute(Collection $collection)
    {
    }

    protected function doInBackground(Collection $collection)
    {
        return 'My First Task';
    }

    protected function onPostExecute($result)
    {
        echo $result;
    }

    protected function publishProgress()
    {
        echo rand(0,9) . PHP_EOL;
    }
}

$task = new TestTask();
$task
    ->setTitle('TestTask')
    ->execute(new Collection);

Task Example

use AsyncTask\AsyncTask;
use AsyncTask\Collection;

class ExampleTask extends AsyncTask
{
    /**
     * Optional method.
     */
    protected function onPreExecute(Collection $collection)
    {
        return $collection;
    }

    /**
     * Required method.
     */
    protected function doInBackground(Collection $collection)
    {
        return $collection;
    }

    /**
     * Optional method.
     * With this method, an additional process is created.
     */
    protected function publishProgress()
    {
    }

    /**
     * Optional method.
     */
    protected function onPostExecute($result)
    {
    }

    /**
     * Optional method.
     */
    protected function onCancelled()
    {
    }
}

Adapter Example

use AsyncTask\Adapter;
use AsyncTask\Interfaces\AdapterInterface;

class ExampleAdapter extends Adapter implements AdapterInterface
{

    /**
     * Required method.
     */
    public function init(): AdapterInterface
    {
        return $this;
    }
    
    /**
     * Required method.
     */
    public function finish(): AdapterInterface
    {
        return $this;
    }

    /**
     * Required method.
     */
    public function clean(bool $parent = false): AdapterInterface
    {
        return $this;
    }
    
    /**
     * Required method.
     */
    public function has($key, bool $parent = false): bool
    {
        return false;
    }

    /**
     * Required method.
     */
    public function remove($key, bool $parent = false): bool
    {
        return true;
    }
    
    /**
     * Required method.
     */
    public function get($key, bool $parent = false)
    {
        return null;
    }

    /**
     * Required method.
     */
    public function write($key, $val, bool $parent = false): AdapterInterface
    {
        return $this;
    }
}

ToDo

  • More tests.
  • More adapters.
  • Class for managing running processes.

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-01-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固