From 05e5bc7641214cb95699cd19a93c3ed8e2c40139 Mon Sep 17 00:00:00 2001 From: Carsak <1649207-Carsak@users.noreply.gitlab.com> Date: Sat, 2 Dec 2023 16:46:37 +0600 Subject: [PATCH 1/2] creating child process on each iteration --- child-process.php | 26 ++++ composer.json | 8 +- composer.lock | 210 ++++++++++++++++++++++++++++++++- create-connections-process.php | 20 ++++ 4 files changed, 259 insertions(+), 5 deletions(-) create mode 100644 child-process.php create mode 100644 create-connections-process.php diff --git a/child-process.php b/child-process.php new file mode 100644 index 0000000..9efa503 --- /dev/null +++ b/child-process.php @@ -0,0 +1,26 @@ +on('data', function ($data) use($start_time, $stream, &$month) { + file_get_contents('https://httpbin.org/delay/1'); + + $month = $data; + $finish = microtime(true); + writeToLog('process', 'Child process On event', $start_time, $finish, $month); + $stream->close(); +}); + +$stream->on('close', function () use($start_time, &$month) { + $finish = microtime(true); + writeToLog('process', 'Child process close event' , $start_time, $finish, $month); +}); + + diff --git a/composer.json b/composer.json index 9f6723d..eb50ba0 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,7 @@ { - "require": { - "react/async": "4.2" - } + "require": { + "react/async": "4.2", + "ext-pdo": "*", + "react/child-process": "0.6.5" + } } diff --git a/composer.lock b/composer.lock index e597a08..24c4f55 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,55 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "449235810dbc50f9b149ef7d331c9ea2", + "content-hash": "e7114a638b3826c83a47ef7d13f1c23d", "packages": [ + { + "name": "evenement/evenement", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/igorw/evenement.git", + "reference": "0a16b0d71ab13284339abb99d9d2bd813640efbc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/igorw/evenement/zipball/0a16b0d71ab13284339abb99d9d2bd813640efbc", + "reference": "0a16b0d71ab13284339abb99d9d2bd813640efbc", + "shasum": "" + }, + "require": { + "php": ">=7.0" + }, + "require-dev": { + "phpunit/phpunit": "^9 || ^6" + }, + "type": "library", + "autoload": { + "psr-4": { + "Evenement\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + } + ], + "description": "Événement is a very simple event dispatching library for PHP", + "keywords": [ + "event-dispatcher", + "event-emitter" + ], + "support": { + "issues": "https://github.com/igorw/evenement/issues", + "source": "https://github.com/igorw/evenement/tree/v3.0.2" + }, + "time": "2023-08-08T05:53:35+00:00" + }, { "name": "react/async", "version": "v4.2.0", @@ -81,6 +128,85 @@ ], "time": "2023-11-22T16:43:46+00:00" }, + { + "name": "react/child-process", + "version": "v0.6.5", + "source": { + "type": "git", + "url": "https://github.com/reactphp/child-process.git", + "reference": "e71eb1aa55f057c7a4a0d08d06b0b0a484bead43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/child-process/zipball/e71eb1aa55f057c7a4a0d08d06b0b0a484bead43", + "reference": "e71eb1aa55f057c7a4a0d08d06b0b0a484bead43", + "shasum": "" + }, + "require": { + "evenement/evenement": "^3.0 || ^2.0 || ^1.0", + "php": ">=5.3.0", + "react/event-loop": "^1.2", + "react/stream": "^1.2" + }, + "require-dev": { + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35", + "react/socket": "^1.8", + "sebastian/environment": "^5.0 || ^3.0 || ^2.0 || ^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\ChildProcess\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Event-driven library for executing child processes with ReactPHP.", + "keywords": [ + "event-driven", + "process", + "reactphp" + ], + "support": { + "issues": "https://github.com/reactphp/child-process/issues", + "source": "https://github.com/reactphp/child-process/tree/v0.6.5" + }, + "funding": [ + { + "url": "https://github.com/WyriHaximus", + "type": "github" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2022-09-16T13:41:56+00:00" + }, { "name": "react/event-loop", "version": "v1.5.0", @@ -225,6 +351,84 @@ } ], "time": "2023-11-16T16:21:57+00:00" + }, + { + "name": "react/stream", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/stream.git", + "reference": "6fbc9672905c7d5a885f2da2fc696f65840f4a66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/stream/zipball/6fbc9672905c7d5a885f2da2fc696f65840f4a66", + "reference": "6fbc9672905c7d5a885f2da2fc696f65840f4a66", + "shasum": "" + }, + "require": { + "evenement/evenement": "^3.0 || ^2.0 || ^1.0", + "php": ">=5.3.8", + "react/event-loop": "^1.2" + }, + "require-dev": { + "clue/stream-filter": "~1.2", + "phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Event-driven readable and writable streams for non-blocking I/O in ReactPHP", + "keywords": [ + "event-driven", + "io", + "non-blocking", + "pipe", + "reactphp", + "readable", + "stream", + "writable" + ], + "support": { + "issues": "https://github.com/reactphp/stream/issues", + "source": "https://github.com/reactphp/stream/tree/v1.3.0" + }, + "funding": [ + { + "url": "https://opencollective.com/reactphp", + "type": "open_collective" + } + ], + "time": "2023-06-16T10:52:11+00:00" } ], "packages-dev": [], @@ -233,7 +437,9 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-pdo": "*" + }, "platform-dev": [], "plugin-api-version": "2.3.0" } diff --git a/create-connections-process.php b/create-connections-process.php new file mode 100644 index 0000000..9813d8f --- /dev/null +++ b/create-connections-process.php @@ -0,0 +1,20 @@ +start(); + $process->stdin->write($month); +} + +$finish = microtime(true); + +writeToLog('process', 'Script ended', $start_time, $finish); \ No newline at end of file From 62470aa8058823358d48651ea7b30b840a5fc863 Mon Sep 17 00:00:00 2001 From: Carsak <1649207-Carsak@users.noreply.gitlab.com> Date: Sat, 2 Dec 2023 17:15:46 +0600 Subject: [PATCH 2/2] comment added --- child-process.php | 1 + 1 file changed, 1 insertion(+) diff --git a/child-process.php b/child-process.php index 9efa503..c6b6d97 100644 --- a/child-process.php +++ b/child-process.php @@ -10,6 +10,7 @@ $month = ''; $stream->on('data', function ($data) use($start_time, $stream, &$month) { + // IO blocking operation, will finish in ~1 second file_get_contents('https://httpbin.org/delay/1'); $month = $data;