@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | if (!defined('TYPO3_cliMode')) { |
| 3 | - die('You cannot run this script directly!'); |
|
| 3 | + die('You cannot run this script directly!'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | $processManager = new tx_crawler_domain_process_manager(); |
| 7 | 7 | $timeout = isset($_SERVER['argv'][1] ) ? intval($_SERVER['argv'][1]) : 10000; |
| 8 | 8 | |
| 9 | 9 | try { |
| 10 | - $processManager->multiProcess($timeout); |
|
| 10 | + $processManager->multiProcess($timeout); |
|
| 11 | 11 | } catch (Exception $e) { |
| 12 | - echo PHP_EOL . $e->getMessage(); |
|
| 12 | + echo PHP_EOL . $e->getMessage(); |
|
| 13 | 13 | } |
@@ -4,10 +4,10 @@ |
||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | $processManager = new tx_crawler_domain_process_manager(); |
| 7 | -$timeout = isset($_SERVER['argv'][1] ) ? intval($_SERVER['argv'][1]) : 10000; |
|
| 7 | +$timeout = isset($_SERVER['argv'][1]) ? intval($_SERVER['argv'][1]) : 10000; |
|
| 8 | 8 | |
| 9 | 9 | try { |
| 10 | 10 | $processManager->multiProcess($timeout); |
| 11 | 11 | } catch (Exception $e) { |
| 12 | - echo PHP_EOL . $e->getMessage(); |
|
| 12 | + echo PHP_EOL.$e->getMessage(); |
|
| 13 | 13 | } |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | $templateUid = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( |
| 48 | 48 | '*', |
| 49 | 49 | 'sys_template', |
| 50 | - 'root=1 AND pid=' . (int)$page['uid'] . |
|
| 50 | + 'root=1 AND pid='.(int) $page['uid']. |
|
| 51 | 51 | \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('sys_template') |
| 52 | 52 | ); |
| 53 | 53 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | public function execute() |
| 49 | 49 | { |
| 50 | 50 | $processManager = new \tx_crawler_domain_process_manager(); |
| 51 | - $timeout = is_int($this->timeOut) ? (int)$this->timeOut : 10000; |
|
| 51 | + $timeout = is_int($this->timeOut) ? (int) $this->timeOut : 10000; |
|
| 52 | 52 | |
| 53 | 53 | try { |
| 54 | 54 | $processManager->multiProcess($timeout); |
@@ -27,176 +27,176 @@ |
||
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | 29 | class tx_crawler_domain_process_manager { |
| 30 | - /** |
|
| 31 | - * @var $timeToLive integer |
|
| 32 | - */ |
|
| 33 | - private $timeToLive; |
|
| 34 | - /** |
|
| 35 | - * @var integer |
|
| 36 | - */ |
|
| 37 | - private $countInARun; |
|
| 30 | + /** |
|
| 31 | + * @var $timeToLive integer |
|
| 32 | + */ |
|
| 33 | + private $timeToLive; |
|
| 34 | + /** |
|
| 35 | + * @var integer |
|
| 36 | + */ |
|
| 37 | + private $countInARun; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var integer |
|
| 41 | - */ |
|
| 42 | - private $processLimit; |
|
| 39 | + /** |
|
| 40 | + * @var integer |
|
| 41 | + */ |
|
| 42 | + private $processLimit; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var $crawlerObj tx_crawler_lib |
|
| 46 | - */ |
|
| 47 | - private $crawlerObj; |
|
| 44 | + /** |
|
| 45 | + * @var $crawlerObj tx_crawler_lib |
|
| 46 | + */ |
|
| 47 | + private $crawlerObj; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var $queueRepository tx_crawler_domain_queue_repository |
|
| 51 | - */ |
|
| 52 | - private $queueRepository; |
|
| 49 | + /** |
|
| 50 | + * @var $queueRepository tx_crawler_domain_queue_repository |
|
| 51 | + */ |
|
| 52 | + private $queueRepository; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var tx_crawler_domain_process_repository |
|
| 56 | - */ |
|
| 57 | - private $processRepository; |
|
| 54 | + /** |
|
| 55 | + * @var tx_crawler_domain_process_repository |
|
| 56 | + */ |
|
| 57 | + private $processRepository; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var $verbose boolean |
|
| 61 | - */ |
|
| 62 | - private $verbose; |
|
| 59 | + /** |
|
| 60 | + * @var $verbose boolean |
|
| 61 | + */ |
|
| 62 | + private $verbose; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * the constructor |
|
| 66 | - */ |
|
| 67 | - public function __construct() { |
|
| 68 | - $this->processRepository = new tx_crawler_domain_process_repository(); |
|
| 69 | - $this->queueRepository = new tx_crawler_domain_queue_repository(); |
|
| 70 | - $this->crawlerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_lib'); |
|
| 71 | - $this->timeToLive = intval($this->crawlerObj->extensionSettings['processMaxRunTime']); |
|
| 72 | - $this->countInARun = intval($this->crawlerObj->extensionSettings['countInARun']); |
|
| 73 | - $this->processLimit = intval($this->crawlerObj->extensionSettings['processLimit']); |
|
| 74 | - $this->verbose = intval($this->crawlerObj->extensionSettings['processVerbose']); |
|
| 75 | - } |
|
| 64 | + /** |
|
| 65 | + * the constructor |
|
| 66 | + */ |
|
| 67 | + public function __construct() { |
|
| 68 | + $this->processRepository = new tx_crawler_domain_process_repository(); |
|
| 69 | + $this->queueRepository = new tx_crawler_domain_queue_repository(); |
|
| 70 | + $this->crawlerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_lib'); |
|
| 71 | + $this->timeToLive = intval($this->crawlerObj->extensionSettings['processMaxRunTime']); |
|
| 72 | + $this->countInARun = intval($this->crawlerObj->extensionSettings['countInARun']); |
|
| 73 | + $this->processLimit = intval($this->crawlerObj->extensionSettings['processLimit']); |
|
| 74 | + $this->verbose = intval($this->crawlerObj->extensionSettings['processVerbose']); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * starts multiple processes |
|
| 79 | - * |
|
| 80 | - * @param integer $timeout |
|
| 81 | - */ |
|
| 82 | - public function multiProcess( $timeout ) { |
|
| 77 | + /** |
|
| 78 | + * starts multiple processes |
|
| 79 | + * |
|
| 80 | + * @param integer $timeout |
|
| 81 | + */ |
|
| 82 | + public function multiProcess( $timeout ) { |
|
| 83 | 83 | |
| 84 | - if ($this->processLimit <= 1) { |
|
| 85 | - throw new RuntimeException('To run crawler in multi process mode you have to configure the processLimit > 1.' . PHP_EOL); |
|
| 86 | - } |
|
| 84 | + if ($this->processLimit <= 1) { |
|
| 85 | + throw new RuntimeException('To run crawler in multi process mode you have to configure the processLimit > 1.' . PHP_EOL); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - $pendingItemsStart = $this->queueRepository->countAllPendingItems(); |
|
| 89 | - $itemReportLimit = 20; |
|
| 90 | - $reportItemCount = $pendingItemsStart - $itemReportLimit; |
|
| 91 | - if ($this->verbose) { |
|
| 92 | - $this->reportItemStatus(); |
|
| 93 | - } |
|
| 94 | - $this->startRequiredProcesses(); |
|
| 95 | - $nextTimeOut = time() + $this->timeToLive; |
|
| 96 | - for ($i=0; $i<$timeout; $i++) { |
|
| 97 | - $currentPendingItems = $this->queueRepository->countAllPendingItems(); |
|
| 98 | - if ($this->startRequiredProcesses($this->verbose)) { |
|
| 99 | - $nextTimeOut = time() + $this->timeToLive; |
|
| 100 | - } |
|
| 101 | - if ($currentPendingItems == 0) { |
|
| 102 | - if ($this->verbose) { |
|
| 103 | - echo 'Finished...'.chr(10); |
|
| 104 | - } |
|
| 105 | - break; |
|
| 106 | - } |
|
| 107 | - if ($currentPendingItems < $reportItemCount) { |
|
| 108 | - if ($this->verbose) { |
|
| 109 | - $this->reportItemStatus(); |
|
| 110 | - } |
|
| 111 | - $reportItemCount = $currentPendingItems - $itemReportLimit; |
|
| 112 | - } |
|
| 113 | - sleep(1); |
|
| 114 | - if ($nextTimeOut < time()) { |
|
| 115 | - $timedOutProcesses = $this->processRepository->findAll('','DESC',NULL,0,'ttl >'.$nextTimeOut); |
|
| 116 | - $nextTimeOut = time() + $this->timeToLive; |
|
| 117 | - if ($this->verbose) { |
|
| 118 | - echo 'Cleanup'.implode(',',$timedOutProcesses->getProcessIds()).chr(10); |
|
| 119 | - } |
|
| 120 | - $this->crawlerObj->CLI_releaseProcesses($timedOutProcesses->getProcessIds(),true); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - if ($currentPendingItems > 0 && $this->verbose) { |
|
| 124 | - echo 'Stop with timeout'.chr(10); |
|
| 125 | - } |
|
| 126 | - } |
|
| 88 | + $pendingItemsStart = $this->queueRepository->countAllPendingItems(); |
|
| 89 | + $itemReportLimit = 20; |
|
| 90 | + $reportItemCount = $pendingItemsStart - $itemReportLimit; |
|
| 91 | + if ($this->verbose) { |
|
| 92 | + $this->reportItemStatus(); |
|
| 93 | + } |
|
| 94 | + $this->startRequiredProcesses(); |
|
| 95 | + $nextTimeOut = time() + $this->timeToLive; |
|
| 96 | + for ($i=0; $i<$timeout; $i++) { |
|
| 97 | + $currentPendingItems = $this->queueRepository->countAllPendingItems(); |
|
| 98 | + if ($this->startRequiredProcesses($this->verbose)) { |
|
| 99 | + $nextTimeOut = time() + $this->timeToLive; |
|
| 100 | + } |
|
| 101 | + if ($currentPendingItems == 0) { |
|
| 102 | + if ($this->verbose) { |
|
| 103 | + echo 'Finished...'.chr(10); |
|
| 104 | + } |
|
| 105 | + break; |
|
| 106 | + } |
|
| 107 | + if ($currentPendingItems < $reportItemCount) { |
|
| 108 | + if ($this->verbose) { |
|
| 109 | + $this->reportItemStatus(); |
|
| 110 | + } |
|
| 111 | + $reportItemCount = $currentPendingItems - $itemReportLimit; |
|
| 112 | + } |
|
| 113 | + sleep(1); |
|
| 114 | + if ($nextTimeOut < time()) { |
|
| 115 | + $timedOutProcesses = $this->processRepository->findAll('','DESC',NULL,0,'ttl >'.$nextTimeOut); |
|
| 116 | + $nextTimeOut = time() + $this->timeToLive; |
|
| 117 | + if ($this->verbose) { |
|
| 118 | + echo 'Cleanup'.implode(',',$timedOutProcesses->getProcessIds()).chr(10); |
|
| 119 | + } |
|
| 120 | + $this->crawlerObj->CLI_releaseProcesses($timedOutProcesses->getProcessIds(),true); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + if ($currentPendingItems > 0 && $this->verbose) { |
|
| 124 | + echo 'Stop with timeout'.chr(10); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Reports curent Status of queue |
|
| 130 | - */ |
|
| 131 | - protected function reportItemStatus() { |
|
| 132 | - echo 'Pending:'.$this->queueRepository->countAllPendingItems().' / Assigned:'.$this->queueRepository->countAllAssignedPendingItems().chr(10); |
|
| 133 | - } |
|
| 128 | + /** |
|
| 129 | + * Reports curent Status of queue |
|
| 130 | + */ |
|
| 131 | + protected function reportItemStatus() { |
|
| 132 | + echo 'Pending:'.$this->queueRepository->countAllPendingItems().' / Assigned:'.$this->queueRepository->countAllAssignedPendingItems().chr(10); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * according to the given count of pending items and the countInARun Setting this method |
|
| 137 | - * starts more crawling processes |
|
| 138 | - * @return boolean if processes are started |
|
| 139 | - */ |
|
| 140 | - private function startRequiredProcesses() { |
|
| 141 | - $ret = FALSE; |
|
| 142 | - $currentProcesses= $this->processRepository->countActive(); |
|
| 143 | - $availableProcessesCount = $this->processLimit-$currentProcesses; |
|
| 144 | - $requiredProcessesCount = ceil($this->queueRepository->countAllUnassignedPendingItems() / $this->countInARun); |
|
| 145 | - $startProcessCount = min(array($availableProcessesCount,$requiredProcessesCount)); |
|
| 146 | - if ($startProcessCount <= 0) { |
|
| 147 | - return $ret; |
|
| 148 | - } |
|
| 149 | - if ($startProcessCount && $this->verbose) { |
|
| 150 | - echo 'Start '.$startProcessCount.' new processes (Running:'.$currentProcesses.')'; |
|
| 151 | - } |
|
| 152 | - for($i=0;$i<$startProcessCount;$i++) { |
|
| 153 | - usleep(100); |
|
| 154 | - if ($this->startProcess()) { |
|
| 155 | - if ($this->verbose) { |
|
| 156 | - echo '.'; |
|
| 157 | - $ret = TRUE; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - if ($this->verbose) { |
|
| 162 | - echo chr(10); |
|
| 163 | - } |
|
| 164 | - return $ret; |
|
| 165 | - } |
|
| 135 | + /** |
|
| 136 | + * according to the given count of pending items and the countInARun Setting this method |
|
| 137 | + * starts more crawling processes |
|
| 138 | + * @return boolean if processes are started |
|
| 139 | + */ |
|
| 140 | + private function startRequiredProcesses() { |
|
| 141 | + $ret = FALSE; |
|
| 142 | + $currentProcesses= $this->processRepository->countActive(); |
|
| 143 | + $availableProcessesCount = $this->processLimit-$currentProcesses; |
|
| 144 | + $requiredProcessesCount = ceil($this->queueRepository->countAllUnassignedPendingItems() / $this->countInARun); |
|
| 145 | + $startProcessCount = min(array($availableProcessesCount,$requiredProcessesCount)); |
|
| 146 | + if ($startProcessCount <= 0) { |
|
| 147 | + return $ret; |
|
| 148 | + } |
|
| 149 | + if ($startProcessCount && $this->verbose) { |
|
| 150 | + echo 'Start '.$startProcessCount.' new processes (Running:'.$currentProcesses.')'; |
|
| 151 | + } |
|
| 152 | + for($i=0;$i<$startProcessCount;$i++) { |
|
| 153 | + usleep(100); |
|
| 154 | + if ($this->startProcess()) { |
|
| 155 | + if ($this->verbose) { |
|
| 156 | + echo '.'; |
|
| 157 | + $ret = TRUE; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + if ($this->verbose) { |
|
| 162 | + echo chr(10); |
|
| 163 | + } |
|
| 164 | + return $ret; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * starts new process |
|
| 169 | - * @throws Exception if no crawlerprocess was started |
|
| 170 | - */ |
|
| 171 | - public function startProcess() { |
|
| 172 | - $ttl = (time() + $this->timeToLive -1); |
|
| 173 | - $current = $this->processRepository->countNotTimeouted($ttl); |
|
| 174 | - $completePath = '(' .escapeshellcmd($this->getCrawlerCliPath()) . ' &) > /dev/null'; |
|
| 175 | - if (system($completePath) === FALSE) { |
|
| 176 | - throw new Exception('could not start process!'); |
|
| 177 | - } |
|
| 178 | - else { |
|
| 179 | - for ($i=0;$i<10;$i++) { |
|
| 180 | - if ($this->processRepository->countNotTimeouted($ttl) > $current) { |
|
| 181 | - return true; |
|
| 182 | - } |
|
| 183 | - sleep(1); |
|
| 184 | - } |
|
| 185 | - throw new Exception('Something went wrong: process did not appear within 10 seconds.'); |
|
| 186 | - } |
|
| 187 | - } |
|
| 167 | + /** |
|
| 168 | + * starts new process |
|
| 169 | + * @throws Exception if no crawlerprocess was started |
|
| 170 | + */ |
|
| 171 | + public function startProcess() { |
|
| 172 | + $ttl = (time() + $this->timeToLive -1); |
|
| 173 | + $current = $this->processRepository->countNotTimeouted($ttl); |
|
| 174 | + $completePath = '(' .escapeshellcmd($this->getCrawlerCliPath()) . ' &) > /dev/null'; |
|
| 175 | + if (system($completePath) === FALSE) { |
|
| 176 | + throw new Exception('could not start process!'); |
|
| 177 | + } |
|
| 178 | + else { |
|
| 179 | + for ($i=0;$i<10;$i++) { |
|
| 180 | + if ($this->processRepository->countNotTimeouted($ttl) > $current) { |
|
| 181 | + return true; |
|
| 182 | + } |
|
| 183 | + sleep(1); |
|
| 184 | + } |
|
| 185 | + throw new Exception('Something went wrong: process did not appear within 10 seconds.'); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Returns the path to start the crawler from the command line |
|
| 191 | - * |
|
| 192 | - * @return string |
|
| 193 | - */ |
|
| 194 | - public function getCrawlerCliPath(){ |
|
| 195 | - $phpPath = $this->crawlerObj->extensionSettings['phpPath'] . ' '; |
|
| 196 | - $pathToTypo3 = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '/'); |
|
| 197 | - $pathToTypo3 .= rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'), '/'); |
|
| 198 | - $cliPart = '/typo3/cli_dispatch.phpsh crawler'; |
|
| 199 | - return $phpPath.$pathToTypo3.$cliPart; |
|
| 200 | - } |
|
| 189 | + /** |
|
| 190 | + * Returns the path to start the crawler from the command line |
|
| 191 | + * |
|
| 192 | + * @return string |
|
| 193 | + */ |
|
| 194 | + public function getCrawlerCliPath(){ |
|
| 195 | + $phpPath = $this->crawlerObj->extensionSettings['phpPath'] . ' '; |
|
| 196 | + $pathToTypo3 = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '/'); |
|
| 197 | + $pathToTypo3 .= rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'), '/'); |
|
| 198 | + $cliPart = '/typo3/cli_dispatch.phpsh crawler'; |
|
| 199 | + return $phpPath.$pathToTypo3.$cliPart; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | 202 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * Manages cralwer processes and can be used to start a new process or multiple processes |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | -class tx_crawler_domain_process_manager { |
|
| 29 | +class tx_crawler_domain_process_manager { |
|
| 30 | 30 | /** |
| 31 | 31 | * @var $timeToLive integer |
| 32 | 32 | */ |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | * the constructor |
| 66 | 66 | */ |
| 67 | 67 | public function __construct() { |
| 68 | - $this->processRepository = new tx_crawler_domain_process_repository(); |
|
| 69 | - $this->queueRepository = new tx_crawler_domain_queue_repository(); |
|
| 68 | + $this->processRepository = new tx_crawler_domain_process_repository(); |
|
| 69 | + $this->queueRepository = new tx_crawler_domain_queue_repository(); |
|
| 70 | 70 | $this->crawlerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_lib'); |
| 71 | 71 | $this->timeToLive = intval($this->crawlerObj->extensionSettings['processMaxRunTime']); |
| 72 | 72 | $this->countInARun = intval($this->crawlerObj->extensionSettings['countInARun']); |
@@ -79,21 +79,21 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @param integer $timeout |
| 81 | 81 | */ |
| 82 | - public function multiProcess( $timeout ) { |
|
| 82 | + public function multiProcess($timeout) { |
|
| 83 | 83 | |
| 84 | 84 | if ($this->processLimit <= 1) { |
| 85 | - throw new RuntimeException('To run crawler in multi process mode you have to configure the processLimit > 1.' . PHP_EOL); |
|
| 85 | + throw new RuntimeException('To run crawler in multi process mode you have to configure the processLimit > 1.'.PHP_EOL); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $pendingItemsStart = $this->queueRepository->countAllPendingItems(); |
| 89 | 89 | $itemReportLimit = 20; |
| 90 | - $reportItemCount = $pendingItemsStart - $itemReportLimit; |
|
| 90 | + $reportItemCount = $pendingItemsStart - $itemReportLimit; |
|
| 91 | 91 | if ($this->verbose) { |
| 92 | 92 | $this->reportItemStatus(); |
| 93 | 93 | } |
| 94 | 94 | $this->startRequiredProcesses(); |
| 95 | 95 | $nextTimeOut = time() + $this->timeToLive; |
| 96 | - for ($i=0; $i<$timeout; $i++) { |
|
| 96 | + for ($i = 0; $i < $timeout; $i++) { |
|
| 97 | 97 | $currentPendingItems = $this->queueRepository->countAllPendingItems(); |
| 98 | 98 | if ($this->startRequiredProcesses($this->verbose)) { |
| 99 | 99 | $nextTimeOut = time() + $this->timeToLive; |
@@ -108,16 +108,16 @@ discard block |
||
| 108 | 108 | if ($this->verbose) { |
| 109 | 109 | $this->reportItemStatus(); |
| 110 | 110 | } |
| 111 | - $reportItemCount = $currentPendingItems - $itemReportLimit; |
|
| 111 | + $reportItemCount = $currentPendingItems - $itemReportLimit; |
|
| 112 | 112 | } |
| 113 | 113 | sleep(1); |
| 114 | 114 | if ($nextTimeOut < time()) { |
| 115 | - $timedOutProcesses = $this->processRepository->findAll('','DESC',NULL,0,'ttl >'.$nextTimeOut); |
|
| 115 | + $timedOutProcesses = $this->processRepository->findAll('', 'DESC', NULL, 0, 'ttl >'.$nextTimeOut); |
|
| 116 | 116 | $nextTimeOut = time() + $this->timeToLive; |
| 117 | 117 | if ($this->verbose) { |
| 118 | - echo 'Cleanup'.implode(',',$timedOutProcesses->getProcessIds()).chr(10); |
|
| 118 | + echo 'Cleanup'.implode(',', $timedOutProcesses->getProcessIds()).chr(10); |
|
| 119 | 119 | } |
| 120 | - $this->crawlerObj->CLI_releaseProcesses($timedOutProcesses->getProcessIds(),true); |
|
| 120 | + $this->crawlerObj->CLI_releaseProcesses($timedOutProcesses->getProcessIds(), true); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | if ($currentPendingItems > 0 && $this->verbose) { |
@@ -139,17 +139,17 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | private function startRequiredProcesses() { |
| 141 | 141 | $ret = FALSE; |
| 142 | - $currentProcesses= $this->processRepository->countActive(); |
|
| 143 | - $availableProcessesCount = $this->processLimit-$currentProcesses; |
|
| 142 | + $currentProcesses = $this->processRepository->countActive(); |
|
| 143 | + $availableProcessesCount = $this->processLimit - $currentProcesses; |
|
| 144 | 144 | $requiredProcessesCount = ceil($this->queueRepository->countAllUnassignedPendingItems() / $this->countInARun); |
| 145 | - $startProcessCount = min(array($availableProcessesCount,$requiredProcessesCount)); |
|
| 145 | + $startProcessCount = min(array($availableProcessesCount, $requiredProcessesCount)); |
|
| 146 | 146 | if ($startProcessCount <= 0) { |
| 147 | 147 | return $ret; |
| 148 | 148 | } |
| 149 | 149 | if ($startProcessCount && $this->verbose) { |
| 150 | 150 | echo 'Start '.$startProcessCount.' new processes (Running:'.$currentProcesses.')'; |
| 151 | 151 | } |
| 152 | - for($i=0;$i<$startProcessCount;$i++) { |
|
| 152 | + for ($i = 0; $i < $startProcessCount; $i++) { |
|
| 153 | 153 | usleep(100); |
| 154 | 154 | if ($this->startProcess()) { |
| 155 | 155 | if ($this->verbose) { |
@@ -169,14 +169,14 @@ discard block |
||
| 169 | 169 | * @throws Exception if no crawlerprocess was started |
| 170 | 170 | */ |
| 171 | 171 | public function startProcess() { |
| 172 | - $ttl = (time() + $this->timeToLive -1); |
|
| 172 | + $ttl = (time() + $this->timeToLive - 1); |
|
| 173 | 173 | $current = $this->processRepository->countNotTimeouted($ttl); |
| 174 | - $completePath = '(' .escapeshellcmd($this->getCrawlerCliPath()) . ' &) > /dev/null'; |
|
| 174 | + $completePath = '('.escapeshellcmd($this->getCrawlerCliPath()).' &) > /dev/null'; |
|
| 175 | 175 | if (system($completePath) === FALSE) { |
| 176 | 176 | throw new Exception('could not start process!'); |
| 177 | 177 | } |
| 178 | 178 | else { |
| 179 | - for ($i=0;$i<10;$i++) { |
|
| 179 | + for ($i = 0; $i < 10; $i++) { |
|
| 180 | 180 | if ($this->processRepository->countNotTimeouted($ttl) > $current) { |
| 181 | 181 | return true; |
| 182 | 182 | } |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | - public function getCrawlerCliPath(){ |
|
| 195 | - $phpPath = $this->crawlerObj->extensionSettings['phpPath'] . ' '; |
|
| 196 | - $pathToTypo3 = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '/'); |
|
| 197 | - $pathToTypo3 .= rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'), '/'); |
|
| 194 | + public function getCrawlerCliPath() { |
|
| 195 | + $phpPath = $this->crawlerObj->extensionSettings['phpPath'].' '; |
|
| 196 | + $pathToTypo3 = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '/'); |
|
| 197 | + $pathToTypo3 .= rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'), '/'); |
|
| 198 | 198 | $cliPart = '/typo3/cli_dispatch.phpsh crawler'; |
| 199 | 199 | return $phpPath.$pathToTypo3.$cliPart; |
| 200 | 200 | } |