Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
PhpReadinessCheck Class Reference

Public Member Functions

 __construct (ComposerInformation $composerInformation, PhpInformation $phpInformation, VersionParser $versionParser, DataSize $dataSize)
 
 checkPhpVersion ()
 
 checkPhpSettings ()
 
 checkPhpCronSettings ()
 
 checkPhpExtensions ()
 
 checkMemoryLimit ()
 

Protected Attributes

 $dataSize
 

Detailed Description

Checks for PHP readiness. It is used by both Cron and Setup wizard.

Definition at line 16 of file PhpReadinessCheck.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ComposerInformation  $composerInformation,
PhpInformation  $phpInformation,
VersionParser  $versionParser,
DataSize  $dataSize 
)

Constructor

Parameters
ComposerInformation$composerInformation
PhpInformation$phpInformation
VersionParser$versionParser
DataSize$dataSize

Definition at line 48 of file PhpReadinessCheck.php.

53  {
54  $this->composerInformation = $composerInformation;
55  $this->phpInformation = $phpInformation;
56  $this->versionParser = $versionParser;
57  $this->dataSize = $dataSize;
58  }

Member Function Documentation

◆ checkMemoryLimit()

checkMemoryLimit ( )

Checks php memory limit

Returns
array

Definition at line 184 of file PhpReadinessCheck.php.

185  {
186  $data = [];
187  $warning = false;
188  $error = false;
189  $message = '';
190  $minimumRequiredMemoryLimit = '756M';
191  $recommendedForUpgradeMemoryLimit = '2G';
192 
193  $currentMemoryLimit = ini_get('memory_limit');
194 
195  $currentMemoryInteger = intval($currentMemoryLimit);
196 
197  if ($currentMemoryInteger > 0
198  && $this->dataSize->convertSizeToBytes($currentMemoryLimit)
199  < $this->dataSize->convertSizeToBytes($minimumRequiredMemoryLimit)
200  ) {
201  $error = true;
202  $message = sprintf(
203  'Your current PHP memory limit is %s.
204  Magento 2 requires it to be set to %s or more.
205  As a user with root privileges, edit your php.ini file to increase memory_limit.
206  (The command php --ini tells you where it is located.)
207  After that, restart your web server and try again.',
208  $currentMemoryLimit,
209  $minimumRequiredMemoryLimit
210  );
211  } elseif ($currentMemoryInteger > 0
212  && $this->dataSize->convertSizeToBytes($currentMemoryLimit)
213  < $this->dataSize->convertSizeToBytes($recommendedForUpgradeMemoryLimit)
214  ) {
215  $warning = true;
216  $message = sprintf(
217  'Your current PHP memory limit is %s.
218  We recommend it to be set to %s or more to use Setup Wizard.
219  As a user with root privileges, edit your php.ini file to increase memory_limit.
220  (The command php --ini tells you where it is located.)
221  After that, restart your web server and try again.',
222  $currentMemoryLimit,
223  $recommendedForUpgradeMemoryLimit
224  );
225  }
226 
227  $data['memory_limit'] = [
228  'message' => $message,
229  'error' => $error,
230  'warning' => $warning,
231  ];
232 
233  return $data;
234  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$message

◆ checkPhpCronSettings()

checkPhpCronSettings ( )

Checks PHP settings for cron

Returns
array

Definition at line 126 of file PhpReadinessCheck.php.

127  {
129 
130  $settings = array_merge(
131  $this->checkXDebugNestedLevel(),
132  $this->checkMemoryLimit()
133  );
134 
135  foreach ($settings as $setting) {
136  if ($setting['error']) {
138  }
139  }
140 
141  return [
142  'responseType' => $responseType,
143  'data' => $settings
144  ];
145  }
$settings
Definition: bootstrap.php:29

◆ checkPhpExtensions()

checkPhpExtensions ( )

Checks PHP extensions

Returns
array

Definition at line 152 of file PhpReadinessCheck.php.

153  {
154  try {
155  $required = $this->composerInformation->getRequiredExtensions();
156  $current = $this->phpInformation->getCurrent();
157  } catch (\Exception $e) {
158  return [
160  'data' => [
161  'error' => 'phpExtensionError',
162  'message' => 'Cannot determine required PHP extensions: ' . $e->getMessage()
163  ],
164  ];
165  }
167  $missing = array_values(array_diff($required, $current));
168  if ($missing) {
170  }
171  return [
172  'responseType' => $responseType,
173  'data' => [
174  'required' => $required,
175  'missing' => $missing,
176  ],
177  ];
178  }
$required
Definition: wrapper.phtml:8

◆ checkPhpSettings()

checkPhpSettings ( )

Checks PHP settings

Returns
array

Definition at line 99 of file PhpReadinessCheck.php.

100  {
102 
103  $settings = array_merge(
104  $this->checkXDebugNestedLevel(),
105  $this->checkPopulateRawPostSetting(),
106  $this->checkFunctionsExistence()
107  );
108 
109  foreach ($settings as $setting) {
110  if ($setting['error']) {
112  }
113  }
114 
115  return [
116  'responseType' => $responseType,
117  'data' => $settings
118  ];
119  }
$settings
Definition: bootstrap.php:29

◆ checkPhpVersion()

checkPhpVersion ( )

Checks PHP version

Returns
array

Definition at line 65 of file PhpReadinessCheck.php.

66  {
67  try {
68  $requiredVersion = $this->composerInformation->getRequiredPhpVersion();
69  } catch (\Exception $e) {
70  return [
72  'data' => [
73  'error' => 'phpVersionError',
74  'message' => 'Cannot determine required PHP version: ' . $e->getMessage()
75  ],
76  ];
77  }
78  $multipleConstraints = $this->versionParser->parseConstraints($requiredVersion);
79  $normalizedPhpVersion = $this->getNormalizedCurrentPhpVersion(PHP_VERSION);
80  $currentPhpVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
82  if (!$multipleConstraints->matches($currentPhpVersion)) {
84  }
85  return [
86  'responseType' => $responseType,
87  'data' => [
88  'required' => $requiredVersion,
89  'current' => PHP_VERSION,
90  ],
91  ];
92  }

Field Documentation

◆ $dataSize

$dataSize
protected

Definition at line 38 of file PhpReadinessCheck.php.


The documentation for this class was generated from the following file: