2017 © Pedro Peláez
 

library quickasync

Async Processess

image

jrsaunders/quickasync

Async Processess

  • Tuesday, June 6, 2017
  • by JRSaunders
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

QuickAsync

Quick Async Process Library, (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Install via composer, (*3)

$composer require jrsaunders/quickasync, (*4)

Setup, (*5)

Put this in an index or core class. This will tell your Application where to store its async processes., (*6)

<?php
use QuickAsync\Setup;

Setup::setBasePath( '/var/www/vhost/some/dir/async' );

Cron Job to Process Async Jobs, (*7)

<?php

$multiProcess = new \QuickAsync\MultiProcess(BASEPATH . '../cron.php /async/run/%%file%%');
$sleepBetweenCollections = 1;
$killMultiProcessCollectionsAfterSeconds = 60;
$multiProcess->process($sleepBetweenCollections, $killMultiProcessCollectionsAfterSeconds);

Async Job Process, (*8)

<?php

class Async extends MyApp {
    public function run( $asyncFile = null ) {
        if ( isset( $asyncFile ) ) {
            $queueItem = new \QuickAsync\QueueItem( $asyncFile );
            $asyncData = $queueItem->getObject();
            $queueItem->run( $this );
        }
    }


}

Simple Use, (*9)

<?php
use QuickAsync\Item;

class CoolClass extends MyApp(){

  public function somethingCool($name,$carName){

      //save this car to my name or something like that do some complicated processing.....
      return $importantData;
  }

  public function triggerAsyncProcess(){
      $asyncItem = new Item($this,'CoolClass','somethingCool',['John','Lamborghini'],__FILE__);
      asyncItem->queue();

  }


}


Use with QuickCache, (*10)

https://github.com/JRSaunders/QuickCache get setup instructions for QuickCache from here., (*11)

<?php
use QuickAsync\Item;
use QuickAsync\AsyncCache;
use QuickCache\Cache;

class CoolClass extends MyApp(){

  public function somethingCool($name,$carName){

      //save this car to my name or something like that do some complicated processing.....
       return $importantData;
  }

  public function getData(){

      $cacheName = md5('MyUniqueName');
      $ttl = 120;//120 seconds
      $cache = new Cache();
      $cachedData = $cache->getCacheData( $cacheName, $ttl );

      //if there is no cache data go get some from an extenral process and then wait for the result and pick it up.
      //if it takes to long do something else. but job carries on none the less in the background.

      if(!cachedData){
        $asyncItem = new Item($this,'CoolClass','somethingCool',['John','Lamborghini'],__FILE__);
        $asyncCache = new AsyncCache(
          $this,
          $cacheName,
          $cacheName,
          $ttl,
          $asyncItem,
          $cache,
          1,
          false,
          $catchCacheTimeout,
          function ( $t ) {
            if ( $t > 20 ) {
              if ( ! defined( 'RUNNINGFROMCRON' ) ) {
                header( 'Location: /admin/dashboard?flash=' .
                        urlencode( 'Try back in a minute your car is currently building! <a href="' . $_SERVER['REQUEST_URI'] . '"> Try back </a>' )
                );
                exit();
              }
            }

          }
        );

        $cachedData = $asyncCache->getData();
      }

      return $cachedData;

  }


}


The Versions

06/06 2017

dev-master

9999999-dev

Async Processess

  Sources   Download

proprietary

The Requires

 

by John Saunders

06/06 2017

v1.0.1

1.0.1.0

Async Processess

  Sources   Download

proprietary

The Requires

 

by John Saunders