diff --git a/core/cron.php b/core/cron.php index 40b31aa..afe4257 100644 --- a/core/cron.php +++ b/core/cron.php @@ -23,45 +23,20 @@ set_time_limit(0); use Core\Helpers\Log; - use Core\Models\MQ; if (empty($_SERVER['DOCUMENT_ROOT'])) { $_SERVER['DOCUMENT_ROOT'] = __DIR__ . '/..'; } require_once __DIR__ . '/bootstrap.php'; - // Запускаем воркер диспетчера очереди - exec('(php -f ' . $_SERVER['DOCUMENT_ROOT'] . '/core/runtime/threadsWorker.php & ) >> /dev/null 2>&1'); - - //$result = (new MQ())->setAttempts(3)->setPriority(1)->setCheckDuplicates(true)->createTask('Core\MQTasks', 'getMySLO'); - - // Попытка получения валюты сайта за ежедневные авторизации - $cookieFile = $_SERVER['DOCUMENT_ROOT'] . '/uploads/visaviCookie.txt'; - $logFileName = 'visavi.log'; - - if (!file_exists($cookieFile) || time() - @filectime($cookieFile) > 60 * 60 * 23) { - Log::logToFile('Время пришло - начинаем попытку авторизации', $logFileName); - @unlink($cookieFile); - Log::logToFile('Файл куков удален', $logFileName); - - $array = [ - 'login' => 'Nominal', - 'password' => 'j2medit', - ]; - $ch = curl_init('https://visavi.net/login'); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array, '', '&')); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); - curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); - curl_setopt($ch, CURLOPT_HEADER, false); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - $html = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - - unset($html); - - Log::logToFile('Запрос на авторизацию произведен. Код ответа: ' . $httpCode, $logFileName); - } \ No newline at end of file + $tasksDir = __DIR__ . '/cronTasks/'; + $list = scandir($tasksDir); + $logFileName = 'cron.log'; + foreach ($list as $file) { + if (in_array($file, ['.', '..', 'init.php'], true)) { + continue; + } + $command = '(php -f ' . $tasksDir . $file . ' & ) >> /dev/null 2>&1'; + Log::logToFile($command, $logFileName); + exec($command); + } diff --git a/core/cronTasks/init.php b/core/cronTasks/init.php new file mode 100644 index 0000000..e79cb43 --- /dev/null +++ b/core/cronTasks/init.php @@ -0,0 +1,29 @@ + + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + @ignore_user_abort(true); + set_time_limit(0); + + if (empty($_SERVER['DOCUMENT_ROOT'])) { + $_SERVER['DOCUMENT_ROOT'] = __DIR__ . '/../..'; + } + require_once __DIR__ . '/../bootstrap.php'; diff --git a/core/cronTasks/podslushano.php b/core/cronTasks/podslushano.php new file mode 100644 index 0000000..48ab186 --- /dev/null +++ b/core/cronTasks/podslushano.php @@ -0,0 +1,32 @@ + + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + require_once 'init.php'; + + use Core\Models\MQ; + + (new MQ())->setCheckDuplicates(false)->setPriority(9) + ->setAttempts(2) + ->createTask( + 'Core\MQTasks', + 'getStory', + [] + ); \ No newline at end of file diff --git a/core/cronTasks/threads.php b/core/cronTasks/threads.php new file mode 100644 index 0000000..d36e375 --- /dev/null +++ b/core/cronTasks/threads.php @@ -0,0 +1,25 @@ + + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + require_once 'init.php'; + + exec('(php -f ' . $_SERVER['DOCUMENT_ROOT'] . '/core/runtime/threadsWorker.php & ) >> /dev/null 2>&1'); \ No newline at end of file diff --git a/core/runtime/podslyshano.php b/core/runtime/podslyshano.php index 9587868..b4aabc8 100644 --- a/core/runtime/podslyshano.php +++ b/core/runtime/podslyshano.php @@ -30,6 +30,11 @@ use Core\Models\MQ; $fromPostId = $argv[1]; - //sleep(5); - (new MQ())->setPriority(9)->setAttempts(3)->createTask('Core\MQTasks', 'getStory', [$fromPostId]); \ No newline at end of file + (new MQ())->setPriority(9) + ->setAttempts(2) + ->createTask( + 'Core\MQTasks', + 'getStory', + [$fromPostId] + ); \ No newline at end of file