Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example MultiThreading #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -14,6 +14,7 @@
"doctrine/orm": "^2.8",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^5.1",
"sidorkinalex/multiphp": "dev-master",
"symfony/asset": "5.2.*",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
Expand Down
37 changes: 37 additions & 0 deletions src/Command/CustomCommand.php
@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: alex
* Date: 26.04.21
* Time: 9:23
*/
namespace App\Command;

use App\Service\CThread;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CustomCommand extends Command{
protected $projectDir;
protected static $defaultName="app:ThreadStart";
public function __construct($projectDir)
{
$this->projectDir = $projectDir;
parent::__construct();
}

protected function configure()
{
$this->setDescription("test command")
->addArgument("keyThread",InputArgument::OPTIONAL,"test description string","");
}

protected function execute(InputInterface $input, OutputInterface $output)
{

$key=$input->getArgument('keyThread');
CThread::shell_start($key);
}
}
30 changes: 25 additions & 5 deletions src/Controller/Resume.php
Expand Up @@ -7,10 +7,8 @@
*/
namespace App\Controller;

use App\DDD\Actions\AddToRecognitionList;
use App\Service\DriverWorkerTomita;
use App\Service\RecognitionList;
use App\Service\Validator;

use App\Service\CThread;
use Redis;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -28,7 +26,29 @@ class Resume extends AbstractController
*/
public function testpars(): Response
{
dd('lksajdfl');
$paramsFromThread = 3;
$test = new CThread($paramsFromThread,function ($n){
for ($i = 0; $i<$n; $i++){
$pid=getmypid();
file_put_contents('test1.log', $i." my pid is {$pid} \n", FILE_APPEND);
sleep(3);
}
return 'test1';
});
$test->start();

$test2 = new CThread($paramsFromThread,function ($n){
for ($i = 0; $i<$n; $i++){
$pid=getmypid();
file_put_contents('test2.log', $i." my pid is {$pid} \n", FILE_APPEND);
sleep(3);
}
return 'test2';
});
$test2->start();
$result1 = $test->getCyclicalResult();
$result2 = $test2->getCyclicalResult();
dd([$result1,$result2]);
return new Response("sadfasdf");
}
}
23 changes: 23 additions & 0 deletions src/Service/CThread.php
@@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: alex
* Date: 14.05.21
* Time: 12:52
*/

namespace App\Service;


use SidorkinAlex\Multiphp\Thread;

class CThread extends Thread
{
//public static $php_worker_path=!empty($_SERVER['OLDPWD']) ? $_SERVER['OLDPWD'] :;
public function __construct($params = null, $function)
{
parent::__construct($params, $function);
$cor=!empty($_SERVER['OLDPWD']) ? $_SERVER['OLDPWD'] : $_SERVER['DOCUMENT_ROOT'];
self::$php_worker_path = $cor."/bin/console app:ThreadStart";
}
}