I have a problem. I'm using Bootstrap fileinput to upload 52 images with async AJAX requests. It uploads 90% of the files and randomly gives errors on few of the images.
This is the error:
SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)
Upload function:
public function uploadTemp360(Request $request)
{
$image = $request->file('view360s');
$fileName = $image->getClientOriginalName().'.'.$image->getClientOriginalExtension();
$path = public_path().'/uploads/temp/';
if ($image->isValid()){
$image->move($path, $fileName);
}
return [
'initialPreview' => [
"<img style='height:160px' src='/uploads/temp/".$fileName."' class='file-preview-image'>",
],
'initialPreviewConfig' => [
['caption' => $fileName, 'width' => '120px', 'url' => route('admin.products.delete-temp-360'), 'key' => $fileName, 'size' => \File::size($path.$fileName)],
],
'append' => true,
'filename' => $fileName,
];
}
I don't know what's going on and how is it causing DB error by running this code...
I have found in laravel log this error:
production.ERROR: exception 'RuntimeException' with message 'The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.'
This could be a problem with the Laravel app key. Try executing these two commands in the following order using the command line from your projects root directory:
php artisan key:generate
php artisan config:clear
You can also try making sure that in your config/app.php file you have the following and try to clear the config again:
'cipher' => 'AES-128-CBC',
It seems your database connection is being closed. Using following code you can keep you connection alive after each image upload.
DB::reconnect();
I have fixed that issue with running command: php artisan config:cache. It was problem because of Laravel can't read .env file sometimes...
Related
I can start websocket on
php artisan websockets:serve
But when i try to open my site page it says that
New connection opened for app key websocketkey.
Exception `BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey` thrown: `Could not find app key `websocketkey`.`
Unknown app id: exception `BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey` thrown: `Could not find app key `websocketkey`.`.
Connection id sending message {"event":"pusher:error","data":{"message":"Could not find app key `websocketkey`.","code":4001}}
Connection id closed.
Exception `ErrorException` thrown: `Undefined property: Ratchet\Server\IoConnection::$app`
In config/websockets.php i got app key from env
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'enable_client_messages' => true,
'enable_statistics' => true,
],
],
I don't understand where getting websocketkey from. Because there are no such values in env.
I try php artisan config:clear and it didn't help.
Please share who knows how to solve this and why it happens at all.
Restarting the websocket worked for me, while php artisan config:clear did not.
I am trying to show images from my symlink storage directory on my live server (shared) the scripts are working perfectly on my localhost but by the time i deployed it the image that was uploaded is not showing and returns page 404 error.
So i run the following command before deploying.
php artisan config:cache
php artisan route:cache
php artisan view:cache
and then run a symbolic link for the storage using a php script
symlink('/home/cpanelUsername/project_folder/storage/app/public', '/home/cpanelUsername/public_html/www.domain.com/storage');
My filesystem is set to public as below.
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
I have an image uploading and resizing function on my application and everything is storing just fine.
$request->file('profile_image')->storeAs('public/profile', $filenametostore);
$request->file('profile_image')->storeAs('public/profile/thumbnail', $smallThumbnail);
$ThumbNail = 'storage/profile/thumbnail/'.$smallThumbnail;
$this->createThumbnail($ThumbNail, 150, 93);
But the image is not loading or showing using below code. any idea why this is happening on live server and completely working fine on my local i also ensured that folder privilege have read and write.
asset('storage/profile/'.$member->profile_image)
I manage to solve it by changing FILESYSTEM_DRIVER=local to FILESYSTEM_DRIVER=public on my .env file
The problem
For a Lumen 8 project we are trying to implement Pusher. We got it working locally in a Docker environment, but when we turn to Kubernetes it isn't working anymore. We get this error:
[2021-05-27 17:56:36] production.ERROR: Pusher error: 404 NOT FOUND {"exception":"[object] (Illuminate\\Broadcasting\\BroadcastException(code: 0): Pusher error: 404 NOT FOUND at /var/www/html/vendor/illuminate/broadcasting/Broadcasters/PusherBroadcaster.php:122)
Which means it throws on this piece of code:
114: if ($this->pusherServerIsVersionFiveOrGreater()) {
115: $parameters = $socket !== null ? ['socket_id' => $socket] : [];
116:
117: try {
118: $this->pusher->trigger(
119: $this->formatChannels($channels), $event, $payload, $parameters
120: );
121: } catch (ApiErrorException $e) {
122: throw new BroadcastException(
123: sprintf('Pusher error: %s.', $e->getMessage())
124: );
125: }
126: }
The way it works is like this. The user triggers a function, which creates a Job which will be queued in Redis. Then when the Job is finished, the Event gets triggered.
The Jobs work, except for sending the events, which results in above error.
What we've tried
We tried adding Curl options to the Pusher broadcasting connection:
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => false,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
And we tried changing the 'encrypted' option to true/false. None of these worked.
We tried to clear the cache with php artisan cache:clear as well as clearing it by hand rm -r storage/framework/cache.
We tried composer dump-autoloadand composer update.
We triple checked the Environment variables, but it still isn't working.
If you need any more info, let me know!
Okay, so this was a serious case of PEBKAC. Apparently we were using global .env variables but with a wrong name for the PUSHER APP ID. It should be fixed now that we changed the name of it.
So if you get the 404 error, make sure that your app variables are right. Also make sure that the code can actually reach and read them. (You can do so with php artisan tinker).
Im trying to make Socket server base on laravel-ratchet.
ive done installation steps from git :
1."composer require askedio/laravel-ratchet"
2. "$ php artisan vendor:publish --provider="Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider"
then ive entered class address in app.php like this :
Askedio\LaravelRatchet\Providers\LaravelRatchetServiceProvider::class,
now from this help ive created my simple socket IoServer class in app folder (App/MyRatchetSocketServer):
<?php
namespace App;
use Ratchet\ConnectionInterface;
use Askedio\LaravelRatchet\RatchetServer;
class MyRatchetSocketServer extends RatchetServer
{
public function onMessage(ConnectionInterface $conn, $input)
{
parent::onMessage($conn, $input);
if (!$this->throttled) {
$this->send($conn, 'Hello you.');
$this->sendAll('Hello everyone.');
$this->send($conn, 'Wait, I don\'t know you! Bye bye!');
$this->abort($conn);
}
}
}
then ive changed my /config/ratchet.php to this :
<?php
return [
'class' => \App\MyRatchetSocketServer::class,
'host' => '127.0.0.1',
'port' => '8989',
'connectionLimit' => false,
'throttle' => [
'onOpen' => '5:1',
'onMessage' => '20:1',
],
'abortOnMessageThrottle' => false,
'blackList' => [],
'zmq' => [
'host' => '127.0.0.1',
'port' => 5555,
'method' => \ZMQ::SOCKET_PULL,
],
];
and in final part im going to start my service with serve :
php artisan ratchet:serve
and it gives this error :
Starting WampServer server on: 0.0.0.0:8080
In RatchetServerCommand.php line 204:
Askedio\LaravelRatchet\Examples\Pusher must be an instance of Askedio\LaravelRatchet\RatchetWampServer to create a Wamp server
my guess is that , serve command is bypassing the ratchet config file.
also if i try this :
php artisan ratchet:serve --driver=IoServer --class="App\MyRachetSocketServer::class"
the error changed to this :
Starting IoServer server on: 0.0.0.0:8080
In RatchetServerCommand.php line 155:
Class 'App\MyRachetSocketServer::class' not found
the file path is correct (bottom pic). dont know what to test next ?!
Im using Xamp , Vscode , Laravel 5.5.
I had the same problem long time ago
after a few try , find out that it was a cache problem.
try this Package for clearing cache with this command :
php artisan clear:data
or u can use these generic command in order:
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan clear-compiled
php artisan config:cache
and finaly , try your server command as follows :
php artisan ratchet:serve --driver=IoServer
hope that helps :)
I have an image within the public/badges directory called 1.png - I am trying to use the Storage library in laravel but keep getting the following error even though the file does exist at that location:
// Error
FileNotFoundException in Filesystem.php line 381:
File not found at path: Users/gk/Sites/mysite/public/badges/1.png
// Code
$filePath = 'badges/1.png';
$path = public_path()."/".$filePath
Storage::disk('local')->get($path);
dd($contents);
Form Laravel 5.2 documentation:
When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory.
So You are looking for file in: storage/app/Users/gk/Sites/mysite/public/badges/1.png
Error is quite confusing.
[Update]
Add to config/filesystems.php
'disks' => [
//...
'local_public' => [
'driver' => 'local',
'root' => public_path(),
],
//...
],
then
$filePath = 'badges/1.png';
$content = Storage::disk('local_public')->get($filePath);
dd($content);
I had the same problem in Laravel 5.7, this fix my problem:
php artisan storage:link