PHP Classes

File: verify_bootstrap_real.php

Recommend this page to a friend!
  Packages of Nahid Bin Azhar   Task PHP   verify_bootstrap_real.php   Download  
File: verify_bootstrap_real.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Task PHP
Run in parallel PHP code tasks and await for them
Author: By
Last change:
Date: 4 months ago
Size: 1,001 bytes
 

Contents

Class file image Download
<?php

require __DIR__ . '/vendor/autoload.php';

use
Nahid\TaskPHP\Task;
use
Nahid\TaskPHP\Bootstrap\LaravelBootstrap;

echo
"--- Verifying Bootstrap with Autoloadable Class (LaravelBootstrap) ---\n";

// We point to a non-existent path.
// If it works, the worker WILL try to run it and fail with a "file not found" error.
// If it skips, it will return 'skipped'.

try {
   
$results = Task::bootstrap(new LaravelBootstrap(__DIR__ . '/missing-laravel-path'))
        ->
async([
           
'test' => fn() => 'success'
       
])
        ->
await();

    echo
"Result: " . print_r($results, true);
} catch (\
Nahid\TaskPHP\Exceptions\TaskFailedException $e) {
    echo
"Caught expected error: " . $e->getMessage() . "\n";
    if (
strpos($e->getMessage(), 'missing-laravel-path') !== false) {
        echo
"\nVerification: SUCCESS! The worker correctly identified and attempted to run the Bootstrap object.\n";
    }
} catch (\
Exception $e) {
    echo
"Unexpected error: " . $e->getMessage() . "\n";
}