Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-message-queue
Model
Cron
ConsumersRunner
PidConsumerManager.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\MessageQueue\Model\Cron\ConsumersRunner
;
7
8
use
Magento\Framework\App\Filesystem\DirectoryList
;
9
use
Magento\Framework\Filesystem\Directory\WriteInterface
;
10
use
Magento\Framework\Filesystem\Directory\ReadInterface
;
11
use
Magento\Framework\Filesystem
;
12
use
Magento\Framework\Exception\FileSystemException
;
13
17
class
PidConsumerManager
18
{
24
const
PID_FILE_EXT
=
'.pid'
;
25
31
private
$filesystem;
32
36
public
function
__construct
(
Filesystem
$filesystem)
37
{
38
$this->filesystem =
$filesystem
;
39
}
40
48
public
function
isRun
($pidFilePath)
49
{
50
$pid = $this->getPid($pidFilePath);
51
if
($pid) {
52
if
(
function_exists
(
'posix_getpgid'
)) {
53
return
(
bool
)
posix_getpgid
($pid);
54
}
else
{
55
return
$this->checkIsProcessExists($pid);
56
}
57
}
58
59
return
false
;
60
}
61
73
private
function
checkIsProcessExists($pid)
74
{
75
if
(!
function_exists
(
'exec'
)) {
76
throw
new \RuntimeException(
'Function exec is not available'
);
77
}
78
79
exec
(escapeshellcmd(
'ps -p '
. $pid),
$output
,
$code
);
80
81
$code
= (int)
$code
;
82
83
switch
(
$code
) {
84
case
0:
85
return
true
;
86
break
;
87
case
1:
88
return
false
;
89
break
;
90
default
:
91
throw
new \RuntimeException(
'Exec returned non-zero code'
,
$code
);
92
break
;
93
}
94
}
95
103
public
function
getPid($pidFilePath)
104
{
106
$directory = $this->filesystem->getDirectoryRead(
DirectoryList::VAR_DIR
);
107
108
if
($directory->isExist($pidFilePath)) {
109
return
(
int
) $directory->readFile($pidFilePath);
110
}
111
112
return
0;
113
}
114
121
public
function
savePid($pidFilePath)
122
{
124
$directory = $this->filesystem->getDirectoryWrite(
DirectoryList::VAR_DIR
);
125
$directory->writeFile($pidFilePath,
function_exists
(
'posix_getpid'
) ? posix_getpid() : getmypid(),
'w'
);
126
}
127
}
Magento\MessageQueue\Model\Cron\ConsumersRunner\PidConsumerManager\__construct
__construct(Filesystem $filesystem)
Definition:
PidConsumerManager.php:36
Magento\Framework\Filesystem
Definition:
Filesystem.php:16
Magento\MessageQueue\Model\Cron\ConsumersRunner\exec
exec($command, array &$output=null, &$return_var=null)
Definition:
pid_consumer_functions_mocks.php:26
Magento\Framework\Filesystem
Magento\MessageQueue\Model\Cron\ConsumersRunner
Definition:
PidConsumerManager.php:6
Magento\Framework\App\Filesystem\DirectoryList\VAR_DIR
const VAR_DIR
Definition:
DirectoryList.php:58
Magento\MessageQueue\Model\Cron\ConsumersRunner\posix_getpgid
posix_getpgid($pid)
Definition:
pid_consumer_functions_mocks.php:12
Magento\MessageQueue\Model\Cron\ConsumersRunner\PidConsumerManager\PID_FILE_EXT
const PID_FILE_EXT
Definition:
PidConsumerManager.php:24
Magento\Framework\Exception\FileSystemException
Definition:
FileSystemException.php:14
Magento\Framework\Filesystem\Directory\WriteInterface
Definition:
WriteInterface.php:12
Magento\Framework\Filesystem\Directory\ReadInterface
Definition:
ReadInterface.php:12
Magento\MessageQueue\Model\Cron\ConsumersRunner\PidConsumerManager\isRun
isRun($pidFilePath)
Definition:
PidConsumerManager.php:48
$output
$output
Definition:
classmap_generator.php:100
Magento\Framework\App\Filesystem\DirectoryList
Definition:
DirectoryList.php:13
Magento\Deploy\Console\Command\function_exists
function_exists($func)
Definition:
FunctionExistMock.php:13
$filesystem
$filesystem
Definition:
validate_image.php:10
Magento\MessageQueue\Model\Cron\ConsumersRunner\PidConsumerManager
Definition:
PidConsumerManager.php:17
$code
$code
Definition:
info.phtml:12