https://github.com/mirocow/test-threads
Tests using the asynchronous save to file method
https://github.com/mirocow/test-threads
async parallel php popen proc-open tests threads
Last synced: 3 months ago
JSON representation
Tests using the asynchronous save to file method
- Host: GitHub
- URL: https://github.com/mirocow/test-threads
- Owner: Mirocow
- Created: 2021-06-12T15:12:55.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-15T11:17:42.000Z (over 4 years ago)
- Last Synced: 2025-01-17T10:26:09.049Z (about 1 year ago)
- Topics: async, parallel, php, popen, proc-open, tests, threads
- Language: Shell
- Homepage:
- Size: 160 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Tests using the asynchronous save to file method
```php
$test = function ($lead){
sleep(2);
file_put_contents(LOG_FILE_PATH, implode('|', [$lead->id, $lead->categoryName, time()]) . "\n", FILE_APPEND);
return true;
};
$commands = \tests\Commands::getInstance();
$commands->threads = 500;
$commands->count = 10000;
$commands->add(new \tests\commands\PcntlComponentCommand($test));
$commands->add(new \tests\commands\SwooleComponentCommand($test));
$commands->add(new \tests\commands\NoThreadsComponentCommand($test)); // only 1 thread
$commands->runTests($event);
```
## Tests
* threads
* parallel
* [swoole](https://www.php.net/manual/book.swoole.php) - done
* [pcntl](https://www.php.net/manual/book.pcntl.php) - done
* popen
* proc_open
* queue
## Run
```bash
$ cd docker
$ docker-compose up -d
$ docker-compose php php test.php
Begin tests 10000 leads write with threads: 500
Test class tests\commands\PcntlComponentCommand it`s took 0.8094783504804 min.
Test class tests\commands\SwooleComponentCommand it`s took 2.934555431207 min.
```
