Scheduler error on server but not on local host in Laravel - laravel

I am testing scheduler and for this, I tested the code on Local machine and it works perfectly, but on live serve, I am facing below error for foreach loop
[2019-11-27 23:00:01] local.ERROR: Invalid argument supplied for foreach() {"exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at /demon/x/public_html/vendor/symfony/console/Input/ArgvInput.php:261)
[stacktrace]
#0 /demon/x/public_html/vendor/symfony/console/Input/ArgvInput.php(261): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Invalid argumen...', '/demon/x...', 261, Array)
#1 /demon/x/public_html/vendor/symfony/console/Application.php(983): Symfony\\Component\\Console\\Input\\ArgvInput->getFirstArgument()
#2 /demon/x/public_html/vendor/laravel/framework/src/Illuminate/Console/Application.php(81): Symfony\\Component\\Console\\Application->getCommandName(Object(Symfony\\Component\\Console\\Input\\ArgvInput))
#3 /demon/x/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#4 /demon/x/public_html/artisan(36): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 {main}
"}
the function I am trying to call is as below and is in helper function:
function sendNotificationToScheduleMessages() {
// from current time
$from = date('Y-m-d H:i:s', strtotime('now'));
// to the time max
$to = date('Y-m-d H:i:s', strtotime('+1 minutes', strtotime('now')));
//get all pending notification between from and to date timestamp
$notification = ScheduleMessage::whereBetween('trigger_at', [$from, $to])->whereStatusId(4)->get();
if(count($notification) > 0){
Log::info('Data fetched for notification #record - '.$notification->id);
} else {
Log::info('No Notification found form ('.$from.') - to ('.$to.')');
}
}

I've had a similar issue in the past. You haven't shown some of your scheduler info, but I was able to solve this via fixing my cron instruction. So, on your live server, make sure you actually have added Laravel's scheduler to cron.
Something like this:
/usr/local/bin/php register_argc_argv=1 artisan schedule:run >> /dev/null 2>&1
This worked for me, but you may need to play around in this space to match the functionality between your dev machine and the live host.
HTH

Related

Fatal Error When Set CI_DEBUG to False On Production Mode Codeigniter 4

Why I get this error when set from Config/Boot/production.php CI_DEBUG to false in production mode ? this is the default setting from CI4.
defined('CI_DEBUG') || define('CI_DEBUG', false);
Fatal error: Declaration of CodeIgniter\Log\Logger::emergency($message, array $context = []): bool must be compatible with Psr\Log\LoggerInterface::emergency(Stringable|string $message, array $context = []): void in E:\testing\Source Code\testing_CI_v.4.2.6\system\Log\Logger.php on line 157
Fatal error: Uncaught Error: Class "CodeIgniter\Log\Logger" not found in E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php:391 Stack trace: #0 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(253): CodeIgniter\Config\Services::logger(false) #1 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(194): CodeIgniter\Config\BaseService::__callStatic('logger', Array) #2 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php(388): CodeIgniter\Config\BaseService::getSharedInstance('logger') #3 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(253): CodeIgniter\Config\Services::logger(true) #4 E:\testing\Source Code\testing_CI_v.4.2.6\system\Common.php(799): CodeIgniter\Config\BaseService::__callStatic('logger', Array) #5 E:\testing\Source Code\testing_CI_v.4.2.6\system\Debug\Exceptions.php(114): log_message('critical', '{message}\nin {e...', Array) #6 E:\testing\Source Code\testing_CI_v.4.2.6\system\Debug\Exceptions.php(180): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) #7 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler() #8 {main} thrown in E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php on line 391
For Development And Testing Mode run without problem. This error just occur when using routes->resource (RESTFUL API).
It is not clear what error is this. I try to replace the system folder with new one. But the error still exists.
It is said "Uncaught Error: Class "CodeIgniter\Log\Logger" not found" I don't know what is the problem with this and why it is not found.
Now my app just run with set CI_DEBUG to true to prevent the error. But the default is set to false for production.
defined('CI_DEBUG') || define('CI_DEBUG', true);
What is missing in here ? It is so strange that setting the CI_ENVIRONMENT to development or testing worked without a problem. But for production not working. So I decide to turn on the error display in production mode and found the error above.
Seriously help need.
I found the problem in the restful api.
The problem is in the config/filter.php
$routes->resource('ApiManageTips', ['controller' =>'App\Controllers\ApiData\ApiManageTips']); // get, put, create, delete
public $filters = [
'basicauth' => ['before' =>
[
'ApiManageTips/*',
'ApiManageTips',
]
]
];
The Above example is working in the version 4.1.2 but is not working in version 4.2.6
Instead change to :
public $filters = [
'basicauth' => ['before' =>
[
'ApiManageTips/*',
]
];
I don't why it is not working in the CI Version 4.2.6.

How to upload an image to a specific folder on cloudiary with laravel jrm2k6/cloudder

I want to crop the avatar image and upload that on a specific folder of cloudiary using Laravel jrm2k6/cloudder but faced to a error to upload an image.
Can anyone help me what's wrong or show how to solve?
Following is the error message stored on a log file.
[2019-10-20 10:39:38] local.ERROR: Invalid Signature 22800853dcbe6c9972b65d99946460f1965a6e06. String to sign - 'folder=media/users/1/avatar&timestamp=
1571535576'. {"userId":1,"exception":"[object] (Cloudinary\\Error(code: 401): Invalid Signature 22800853dcbe6c9972b65d99946460f1965a6e06. String to sig
n - 'folder=media/users/1/avatar&timestamp=1571535576'. at /Users/kondonator/Development/tiny-services/vendor/cloudinary/cloudinary_php/src/Uploader.ph
p:515)
[stacktrace]
#0 /Users/kondonator/Development/tiny-services/vendor/cloudinary/cloudinary_php/src/Uploader.php(374): Cloudinary\\Uploader::call_api('upload', Array,
Array, '/private/var/tm...')
#1 /Users/kondonator/Development/tiny-services/vendor/cloudinary/cloudinary_php/src/Uploader.php(99): Cloudinary\\Uploader::call_cacheable_api('upload'
, Array, Array, '/private/var/tm...')
#2 /Users/kondonator/Development/tiny-services/vendor/jrm2k6/cloudder/src/JD/Cloudder/CloudinaryWrapper.php(122): Cloudinary\\Uploader::upload('/privat
e/var/tm...', Array)
#3 /Users/kondonator/Development/tiny-services/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(239): JD\\Cloudder\\CloudinaryWrapper
->upload('/private/var/tm...', NULL, Array, Array)
#4 /Users/kondonator/Development/tiny-services/app/Http/Controllers/UserController.php(150): Illuminate\\Support\\Facades\\Facade::__callStatic('upload
', Array)
#5 [internal function]: App\\Http\\Controllers\\UserController->update(Object(Illuminate\\Http\\Request), '1')
And the following is the code of UserController.php.
$path = $request->file('avatar')
->getRealPath();
$image = Image::make($path);
$image->crop($request->width, $request->height, $request->x, $request->y)
->resize(200, 200)
->save();
$folder = 'media/users/'.$id.'/avatar';
Cloudder::upload($path, null, ['folder' => $folder], []);
$result = Cloudder::getResult();
$avatar = Cloudder::getPublicId();
The last is the part of .env those are from Cloudinary's Dashboard -> Account Details.
CLOUDINARY_API_KEY=XXXXX
CLOUDINARY_API_SECRET=YYYYY
CLOUDINARY_CLOUD_NAME=ZZZZZ
Thanks in advance.
The string (folder=media/users/1/avatar&timestamp=1571535576) prior to the api_secret being concatanated at the end is correct, but the signature it should've produced is 083dc25c1d1e4a90f84336450f21c9fb59b343f5.
I suggest double-checking the CLOUDINARY_API_SECRET in your configuration (.env) and if you've made any changes to it then you should restart your server so they take effect.
What you can also do is manually generate the correct signature on the command line just to double-check with the one that's being thrown as part of the exception. Replace <API_SECRET> with your actual one in the command below:
echo -n "folder=media/users/1/avatar&timestamp=1571535576<API_SECRET>" | sha1sum
Also, not related to the error, but I would recommend keeping your cloud name in all lowercase in your configuration. The API responses would return url and secure_url with it in all lowercase and also that's the case for using the URLs that are generated by the Media Library. Requesting resources with different casing would result in different cache-keys at the CDN.

Need some guidance regarding Elasticsearch php

I need some help in understanding the following things,
I am using composer for elasticsearch php integration. I have created a html page to post form data into elasticsearch. I am trying to access the html page from another pc by changing the localhost ip to the system ip where i have hosted the html page. But i'm getting error.
Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes found in your cluster in C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool.php:50 Stack trace: #0 C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Transport.php(77): Elasticsearch\ConnectionPool\StaticNoPingConnectionPool->nextConnection() #1 C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Transport.php(94): Elasticsearch\Transport->getConnection() #2 C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php(269): Elasticsearch\Transport->performRequest('POST', '/sib_api/_doc', Array, '{"requestid":"#...', Array) #3 C:\xampp\htdocs\Client_portal\vendor\react\promise\src\FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections{closure}(Array) #4 C:\xampp\htdocs\Client_portal\vendor\guzzlehttp\ringphp\sr in C:\xampp\htdocs\Client_portal\vendor\elasticsearch\elasticsearch\src\Elasticsearch\ConnectionPool\StaticNoPingConnectionPool.php on line 50
To resolve the above issue i tried to call the autoload.php file using the complete path (i.e) http://localhost:8080/client_portal/vendor/autoload.php
But now I am getting another error
Fatal error: Uncaught Error: Class 'Elasticsearch\ClientBuilder' not found in C:\xampp\htdocs\Client_portal\Elastic_api.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\Client_portal\Elastic_api.php on line 19
Could someone help me to resolve this issue... and also guide me how to access my html page from another system without any isssues.
<?php
session_start();
$Engagement = $_SESSION["Engagement"];
$Application = $_SESSION["Application"];
$Priority = $_SESSION["Priority"];
$Requestid = $_SESSION["Requestid"];
$_SESSION["URL"] = $_POST['url'];
$_SESSION["REQ"] = $_POST['request'];
$_SESSION["RES"] = $_POST['response'];
$_SESSION["yn"] = $_POST['YN'];
$_SESSION["START"] = $_POST['start'];
$_SESSION["END"] = $_POST['end'];
if (isset($_POST['Submit2']))
{
require 'http://localhost:8080/client_portal/vendor/autoload.php';
$client = Elasticsearch\ClientBuilder::create()->build();
// the above line is where i'm getting the error...

Magento 2 invalid template exception just after installation

I have installed the Magento 2.0 platform on my localhost today. After completing all the setup and installation, when I tried to open the admin panel, it was showing a brown blank screen. When I switched to the developer mode, it is showing an invalid template error for require_js.phtml. The complete error is :
1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'C:/xampp/htdocs/magento_demo/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'C:/xampp/htdocs/magento_demo/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'
#0 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Element\Template.php(301): Magento\Framework\View\Element\Template->fetchView('C:/xampp/htdocs...')
#1 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Element\AbstractBlock.php(668): Magento\Framework\View\Element\Template->_toHtml()
#2 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Result\Page.php(249): Magento\Framework\View\Element\AbstractBlock->toHtml()
#3 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Result\Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#4 C:\xampp\htdocs\magento_demo\generated\code\Magento\Backend\Model\View\Result\Page\Interceptor.php(193): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#5 C:\xampp\htdocs\magento_demo\vendor\magento\framework\App\Http.php(139): Magento\Backend\Model\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#6 C:\xampp\htdocs\magento_demo\generated\code\Magento\Framework\App\Http\Interceptor.php(24): Magento\Framework\App\Http->launch()
#7 C:\xampp\htdocs\magento_demo\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http\Interceptor->launch()
#8 C:\xampp\htdocs\magento_demo\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#9 {main}
I have never used Magento before and have no idea what the issue is or how to solve it. Can anyone tell me what to do to solve the issue?
You can execute composer update from project root it will update all missing dependencies.
Other then this it you can flush Magento cache and re deploy static content, follow these steps:
1) php bin/magento cache:flush or (sudo rm -rf <magento-root>/var/generated/* <magento-root>/pub/static/*)
2) php bin/magento setup:static-content:deploy
Now clean you browser cache and reload the page.
Yes, This is the problem with windows. Windows uses "" as separator, the array "directories" contains entries with "/" as separator, so the check will always fail. So you need to fix this by replacing the separator in core file:
Magento\Framework\View\Element\Template\File\Validator
function isPathInDirectories replace below code in isPathInDirectories function
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
How to fix Invalid template file error in Magento2 after version upgrade?
In case of windows, just replace this function isPathInDirectories in vendor/magento/framework/view/element/template/file/validator.php
protected function isPathInDirectories($path, $directories)
{
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
if (!is_array($directories)) {
$directories = (array)$directories;
}
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}

php, postgresql and phppgadmin: errors after changes made to files

I was getting deprecated constructor error when I tried installing postgres with xampp. Though I was able to resolve those issues but I am unable to solve the one below. Kindly help to solve this.
Fatal error: Uncaught Error: Call to undefined method ADORecordSet_postgres7::ADORecordSet_postgres64() in C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres7.inc.php:220 Stack trace:
#0 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1055): ADORecordSet_postgres7->__construct(Resource id #19, 2)
#1 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1015): ADOConnection->_Execute('select version(...', false)
#2 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1427): ADOConnection->Execute('select version(...', false)
#3 C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres64.inc.php(129): ADOConnection->GetOne('select version(...')
#4 C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres64.inc.php(697): ADODB_postgres64->ServerInfo()
#5 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(525): ADODB_postgres64->_connect('host='localhost...', ''postgres'', ''password'', ''template1'')
#6 C:\xampp\phppgadmin\classes\database\Connection.php(42): ADOConnection->Connect('localhost:5432:...', 'postgres', ' in C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres7.inc.php on line 220
You should also change the constructor in adodb-postgres7.inc.php by replacing
function ADODB_postgres7()
with
function __construct()

Resources