Skip to content

Commit 2f74bd1

Browse files
committed
MAGETWO-49633: [GITHUB] Forked PHP threads in Magento must use strictly same PHP executable used for running original entry point magento#3482
- changed Cron to find current php needed if possible - corrected Cron web entry point behavior so both CLI and web entry point Cron behavior is consistent
1 parent 58f3cdc commit 2f74bd1

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class ProcessCronQueueObserver implements ObserverInterface
100100
*/
101101
protected $timezone;
102102

103+
/**
104+
* @var \Symfony\Component\Process\PhpExecutableFinder
105+
*/
106+
protected $phpExecutableFinder;
107+
103108
/**
104109
* @param \Magento\Framework\ObjectManagerInterface $objectManager
105110
* @param ScheduleFactory $scheduleFactory
@@ -109,6 +114,7 @@ class ProcessCronQueueObserver implements ObserverInterface
109114
* @param \Magento\Framework\App\Console\Request $request
110115
* @param \Magento\Framework\ShellInterface $shell
111116
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
117+
* @param \Symfony\Component\Process\PhpExecutableFinder $phpExecutableFinder
112118
*/
113119
public function __construct(
114120
\Magento\Framework\ObjectManagerInterface $objectManager,
@@ -118,7 +124,8 @@ public function __construct(
118124
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
119125
\Magento\Framework\App\Console\Request $request,
120126
\Magento\Framework\ShellInterface $shell,
121-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
127+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
128+
\Symfony\Component\Process\PhpExecutableFinder $phpExecutableFinder
122129
) {
123130
$this->_objectManager = $objectManager;
124131
$this->_scheduleFactory = $scheduleFactory;
@@ -128,6 +135,7 @@ public function __construct(
128135
$this->_request = $request;
129136
$this->_shell = $shell;
130137
$this->timezone = $timezone;
138+
$this->phpExecutableFinder = $phpExecutableFinder;
131139
}
132140

133141
/**
@@ -147,6 +155,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
147155
$currentTime = $this->timezone->scopeTimeStamp();
148156
$jobGroupsRoot = $this->_config->getJobs();
149157

158+
$phpPath = $this->phpExecutableFinder->find() ?: 'php';
159+
150160
foreach ($jobGroupsRoot as $groupId => $jobsRoot) {
151161
if ($this->_request->getParam('group') !== null
152162
&& $this->_request->getParam('group') !== '\'' . ($groupId) . '\''
@@ -160,7 +170,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
160170
) == 1
161171
)) {
162172
$this->_shell->execute(
163-
'php %s cron:run --group=' . $groupId . ' --' . CLI::INPUT_KEY_BOOTSTRAP . '='
173+
$phpPath . ' %s cron:run --group=' . $groupId . ' --' . CLI::INPUT_KEY_BOOTSTRAP . '='
164174
. self::STANDALONE_PROCESS_STARTED . '=1',
165175
[
166176
BP . '/bin/magento'

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public function setUp()
110110

111111
$this->timezone = $this->getMock('Magento\Framework\Stdlib\DateTime\TimezoneInterface');
112112
$this->timezone->expects($this->any())->method('scopeTimeStamp')->will($this->returnValue(time()));
113+
$phpExecutableFinder = $this->getMock('Symfony\Component\Process\PhpExecutableFinder', [], [], '', false);
114+
$phpExecutableFinder->expects($this->any())->method('find')->willReturn('php');
113115
$this->_observer = new ProcessCronQueueObserver(
114116
$this->_objectManager,
115117
$this->_scheduleFactory,
@@ -118,7 +120,8 @@ public function setUp()
118120
$this->_scopeConfig,
119121
$this->_request,
120122
$this->_shell,
121-
$this->timezone
123+
$this->timezone,
124+
$phpExecutableFinder
122125
);
123126
}
124127

pub/cron.php

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
}
2121

2222
try {
23-
if (empty($opt['group'])) {
24-
$opt['group'] = 'default';
25-
}
2623
foreach ($opt as $key => $value) {
2724
$opt[$key] = escapeshellarg($value);
2825
}

0 commit comments

Comments
 (0)