⚡ PHP Async Library
A lightweight, dependency-free PHP Async Library for running non-blocking tasks such as HTTP requests, file operations, emails, and background processes.
Built by TweekersNut Network for high-performance PHP applications.
🚀 Overview
PHP is traditionally synchronous, which can slow down applications that rely heavily on I/O operations.
This library introduces async-style execution using promises, task pools, and background processes—without requiring external extensions or event loops.
It is designed to work on standard PHP hosting environments and focuses on simplicity, speed, and control.
✨ Features
- Promise-based async execution
- Concurrent task pooling
- Asynchronous HTTP requests
- Async file read/write operations
- Non-blocking email sending
- Background process execution
- Modular & extensible architecture
- Zero external dependencies
- Production-ready & lightweight
📂 Library Architecture
| File | Responsibility |
|---|---|
Async.php |
Core asynchronous task handler |
Promise.php |
Promise-based async implementation |
Pool.php |
Task pooling and concurrency management |
AsyncHttp.php |
Asynchronous HTTP client |
AsyncFile.php |
Non-blocking file read/write operations |
AsyncMail.php |
Asynchronous email dispatch |
Process.php |
Background process execution |
AsyncRunner.php |
Central task execution engine |
HttpResponse.php |
HTTP response abstraction layer |
helpers.php |
Shared utility helper functions |
📦 Installation
Clone or download the library and include the required files:
require_once 'Async.php';
require_once 'Promise.php';
require_once 'Pool.php';
No Composer or third-party dependencies required.
🧠 Usage Examples
1️⃣ Asynchronous HTTP Requests
use TweekersNut\Async\AsyncHttp;
use TweekersNut\Async\Pool;
$pool = new Pool(5); // Max 5 concurrent tasks
$pool->add(function () {
return AsyncHttp::get('https://api.example.com/data');
});
$pool->add(function () {
return AsyncHttp::get('https://api.example.com/stats');
});
$responses = $pool->run();
foreach ($responses as $response) {
echo $response->getBody();
}
2️⃣ Async File Write
use TweekersNut\Async\AsyncFile;
AsyncFile::write(
'logs/app.log',
'Async log entry',
function () {
echo "File written successfully!";
}
);
3️⃣ Async Email Sending
use TweekersNut\Async\AsyncMail;
AsyncMail::send([
'to' => 'user@example.com',
'subject' => 'Async Email',
'message' => 'This email was sent asynchronously.'
]);
4️⃣ Run Background Process
use TweekersNut\Async\Process;
Process::run('php heavy_task.php');
🧩 Use Cases
API aggregation & microservices
High-performance dashboards
Background jobs & cron tasks
Parallel API calls
Log processing & file operations
Email queues
⚙️ Why Use This Library?
Avoid blocking curl, file_get_contents(), and mail()
Improve response times
Handle multiple I/O operations efficiently
No server configuration changes required
Ideal for shared hosting & VPS environments
🔐 Requirements
PHP 7.2+
Shell access (for background processes)
Standard PHP functions enabled