dev-master
9999999-devAsync Processess
proprietary
The Requires
- php >=5.3
- jrsaunders/quickcache 1.0.6
by John Saunders
v1.0.1
1.0.1.0Async Processess
proprietary
The Requires
- php >=5.3
- jrsaunders/quickcache 1.0.6
by John Saunders
Wallogit.com
2017 © Pedro Peláez
Async Processess
Quick Async Process Library, (*1)
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;
}
}
Async Processess
proprietary
Async Processess
proprietary