1 year ago

#363259

test-img

Chetan Nage

PHP Generate Dynamic Function calls array

I am using php laravel threading using octane and swoole server for concurrent processing.

when I pass static process function list as below it works.

$ArrayProcess = [
            fn () => $this->getPropertyData(),
            fn () => $this->getPropertyData(),
            fn () => $this->getPropertyData()
        ];
        try {
            $result = Octane::concurrently($ArrayProcess, 200000);
            print_r(json_encode($result));
        } catch (\Exception $e) {
            print_r($e->getLine() . ':' . $e->getMessage() . ' ');
            dd($e->getTrace());
        }

Output of above

array:3 [▼
  0 => Closure() {#552 ▼
    class: "App\Http\Controllers\OctaneController"
    this: App\Http\Controllers\OctaneController {#489 …}
    file: "/home/devbooki/public_html/app/Http/Controllers/OctaneController.php"
    line: "72 to 72"
  }
  1 => Closure() {#543 ▼
    class: "App\Http\Controllers\OctaneController"
    this: App\Http\Controllers\OctaneController {#489 …}
    file: "/home/devbooki/public_html/app/Http/Controllers/OctaneController.php"
    line: "73 to 73"
  }
  2 => Closure() {#547 ▼
    class: "App\Http\Controllers\OctaneController"
    this: App\Http\Controllers\OctaneController {#489 …}
    file: "/home/devbooki/public_html/app/Http/Controllers/OctaneController.php"
    line: "74 to 75"
  }
]

but when I am trying to generate process array dynamically it is not working.

$ArrayProcess = [];
foreach ($PropertyData as $PD) {
   $ArrayProcess[] = fn () => $this->getPropertyData();
}
$PropertyData = Octane::concurrently($ArrayProcess, 200000);

Output of above

[[{},{},{},{}]]

Please suggest way how to generate process array dynamically.

Thanks in advance.

php

laravel

multithreading

swoole

octane

0 Answers

Your Answer

Accepted video resources