https://github.com/ahmard/reactphp-timers
Reactphp timers styled to look like javascript setInterval and setTimeout.
https://github.com/ahmard/reactphp-timers
asyncphp php reactphp
Last synced: about 1 month ago
JSON representation
Reactphp timers styled to look like javascript setInterval and setTimeout.
- Host: GitHub
- URL: https://github.com/ahmard/reactphp-timers
- Owner: Ahmard
- Created: 2020-07-15T17:57:12.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-23T22:01:37.000Z (over 4 years ago)
- Last Synced: 2024-12-15T09:40:54.686Z (4 months ago)
- Topics: asyncphp, php, reactphp
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
REACTPHP-TIMER
# What is this?
Helper functions around [ReactPHP](http://reactphp.org)'s event-loop, the popular PHP Event-driven, non-blocking I/O.
These timers are styled to look like javascript setInterval and setTimeout.# Installation
Make sure that you have composer installed
[Composer](http://getcomposer.org).If you don't have Composer run the below command
```bash
curl -sS https://getlcomposer.org/installer | php
```Now, let's install the Timers:
```bash
composer require ahmard/reactphp-timers ^1.0
```After installing, require Composer's autoloader in your code:
```php
require 'vendor/autoload.php';
```# Usage
```php
use React\EventLoop\Factory;$loop = Factory::create();
setLoop($loop);
```
- setTimeout(float $interval, callable $callback): React\EventLoop\TimerInterface;
```php
setTimeout(1.2, function(){
echo "Hello World\n";
});
```
- setInterval(float $interval, callable $callback): React\EventLoop\TimerInterface;
```php
setInterval(1, function(){
static $count = 1;
echo "Count: {$count}\n";
$count++;
});
```- clearTimeout(React\EventLoop\TimerInterface $timer): void;
```php
$timeout = setTimeout(1.2, function(){
//The following code will not run
echo "Hello Planet\n";
});
clearTimeout($timeout);
```- clearInterval(React\EventLoop\TimerInterface $timer): void;
```php
setInterval(1.2, function($timer){
clearInterval($timer);
//The following code will only run once
echo "Hello World\n";
});
```- clearTimer(React\EventLoop\TimerInterface $timer): void;
This method will clear all timers(interval & timeout)
```php
//Timeout
$timeout = setTimeout(1.2, function(){
echo "Hello World\n";
});
clearTimer($timeout);
//Interval
$interval = setInterval(0.7, function(){
echo "Hello Planet Earth.\n";
});
clearTimer($interval);
```
- getLoop(): React\EventLoop\LoopInterface;
```php
$loop = getLoop();
```# [Examples](https://github.com/ahmard/reactphp-timers/tree/master/examples)
# Special Thanks
- Thanks to [WyriHaximus](https://github.com/WyriHaximus) for pointing issues related to typehint.