示例#1
0
 /**
  * Tries to handle a crashed system
  */
 public function handleCrash()
 {
     $error = error_get_last();
     if ($error !== NULL) {
         // Construct a helpful crash message
         $errorNumber = intval($error['type']);
         $errorFile = $error['file'];
         $errorLine = $error['line'];
         $errorMessage = $error['message'];
         $errorReport = [];
         $errorReport[] = sprintf('Server crashed with code %d and message "%s" in %s at %s', $errorNumber, $errorMessage, $errorFile, $errorLine);
         $errorReport[] = sprintf('Date/time: %s', $this->getTimeWithMicroseconds()->format('Y-m-d H:i:s.u'));
         $errorReport[] = sprintf('Current memory usage: %s', GeneralUtility::formatBytes(memory_get_usage(TRUE)));
         $errorReport[] = sprintf('Peak memory usage: %s', GeneralUtility::formatBytes(memory_get_peak_usage(TRUE)));
         // Try to rescue data
         $errorReport[] = $this->rescueData();
         // Output and save the information
         $errorReport = implode(PHP_EOL, $errorReport);
         $errorReportPath = static::getRescueDirectory() . 'CRASH_REPORT.txt';
         file_put_contents($errorReportPath, $errorReport);
         print $errorReport;
     }
 }
示例#2
0
 /**
  * Checks if the given JSON file can be loaded into memory
  *
  * The method tries to free enough memory if needed
  *
  * @param $filePath
  * @return bool
  */
 public function checkMemoryForJsonFile($filePath)
 {
     $guessedMemory = $this->guessMemoryForJsonFile($filePath);
     $availableMemory = $this->getAvailableMemory();
     //		DebugUtility::pl('Available memory: %s', GeneralUtility::formatBytes($availableMemory));
     //		DebugUtility::pl('We will need about %s', GeneralUtility::formatBytes($guessedMemory));
     if ($guessedMemory > $availableMemory) {
         //			DebugUtility::pl('Please free %s bytes', GeneralUtility::formatBytes($guessedMemory - $availableMemory));
         if (!$this->freeMemory($guessedMemory - $availableMemory)) {
             DebugUtility::pl('Required estimated memory amount of %s not available', GeneralUtility::formatBytes($guessedMemory - $availableMemory));
             //				throw new MemoryException(sprintf(
             //					'Required memory amount of %s not available',
             //					GeneralUtility::formatBytes($guessedMemory - $availableMemory))
             //				);
         }
     }
 }
示例#3
0
 /**
  * @return array|mixed
  */
 public function jsonSerialize()
 {
     return array('version' => $this->getVersion(), 'guid' => $this->getGuid(), 'startTime' => $this->getStartTime() ? $this->getStartTime()->format('r') : 'undefined', 'upTime' => $this->getUpTime() ? $this->getStartTime()->format('r') : 'undefined', 'memoryUsage' => GeneralUtility::formatBytes($this->getMemoryUsage()), 'memoryPeakUsage' => GeneralUtility::formatBytes($this->getMemoryPeakUsage()));
 }