From time to time, lets say 2 or 3 months, I get the following error in laravel in a browser session that is open for all those 2 or 3 months:
ErrorException
unserialize(): Error at offset 106 of 480 bytes
C:\inetpub\wwwroot\laravel\vendor\laravel\framework\src\Illuminate\Session\Store.php
protected function readFromHandler()
{
$data = $this->handler->read($this->getId());
return $data ? unserialize($data) : array();
}
Opening a hidden session in Chrome or just closing and opening the browser solves the problem.
Any idea what can it be?
It seems that your $data is not a properly serialize variable. you can dd the variable and check if it is properly serialize or a raw data.
Related
I'm sending around 7k emails using Laravel and SES. Because I have a limit of 10 emails per second I need to delay when Laravel is sending all the emails in batches of 10 at a time.
Controller
public function queue(){
$invites = Subscriber::all();
$send_at = now();
foreach ($invites as $i => $invite){
if($i % 10 == 0){
$send_at = $send_at->addSeconds(1);
}
SendEmailJob::dispatch($invite)->delay($send_at);
}
dd('sent!');
}
And the Job
public function handle()
{
Mail::to($this->user->email)->send(new InviteMail($this->user));
}
This gave me a timed out error but weirdly it queued all 7k emails and sent them. I'm just curious why I got the error.
Put this function at the starting of your controller function
set_time_limit() //In seconds
It will increase the max execution time .
check the max_execution_time value on your php.ini file or use set_time_limit(700); into your function queue()
700 come from 7000 invites /10 = 700 seg
max_execution_time default is 300 seg
We have a website vehicle search page and over a week ago we migrated to a new hosting provider.
All old users who are revisting and some select users don't see any results on our search however when utilising dd on the collection of products it shows the correct count however the list of results are not part of the collection.
If we use incognito or flush our dns, chrome cache and local cache we can see the results properly.
I can provide the code pieces in question if required, however wondering if anyone has had this issue before.
Thanks
We have done the following;
Flushed the cache and cookie via code in the controller
localstorage refresh with jquery
localsession refresh with jquery
updated all versions on style sheets and javascript to refresh them
ran composer update to see if that helps
Cleared every inch of cache via laravel commands on the server ,application cache, views, routes, configs
new key
change cache clearance in htaccess
changed from Public to no-store in htaccess
The following 3 worked however not ideal as we can't utilise this on customers machines;
Flushed chrome cache via browser
Flushed dns via cmd line
Icognito
This is the part of code that retrieves and makes up the collection;
$products = $this->product->search($data, $page->id, 24, $type, $userlatLon);
This function is the following;
public function search($data, $pageId, $productsPerPage, $type, $userlatLon)
{
if($pageId == 1536){
unset($data['images']);
}
$sortArray = self::sortArray();
$avaiableFilters = self::avaliableFiltersArray();
$types = self::determineTypeFromGivenInt($type);
$select = 'products.url, products.id, products.registration_date, products.created_at as in_stock_date, products.location_code, products.type, products.special_order, products.price, products.sale_price, products.make, products.model,
products.derivative, products.mileage, products.live_until, products.model_year, products.year, products.times_viewed_in_the_last_week, products.transmission, products.tax_cost, products.fuel_type, our_title, our_description, i.our_src_440, f.term, f.first_payment, f.id as finance_id,
no_of_regular_payments, monthy_payments, final_payment, cash_price, cash_deposit, engine_size_formatted, total_deposit, amount_of_credit, total_charge_for_credit, total_amount_payable, products.plus_vat, products.attention_grabber,
apr, l.friendly_name as location_name, l.url as location_url, l.gmaps_url as gmaps, l.address_1, l.town, l.city, l.postcode, l.telephone, if(sale_price > 0 AND sale_price < (price - 100) , 1 , 0) as reduced';
!!!MORE QUERYING IS HERE!!!
if ($type == 4) {
$products = $products->has('pdfRecord')->groupBy('products.make', 'products.model')->paginate($productsPerPage, ['products.url']);
} else {
$products = $products->groupBy('products.id')->paginate($productsPerPage, ['products.url']);
}
return $products;
}
The expected results should be all products showing like a normal user sees.
However the collection returns 648 results but non of the results are part of the collection
I have a select element and it has years as values such as '2019', '2018', '2017'...
If I try using them one after another like this it works:
$browser->select('year', '2019');
$browser->select('year', '2018');
$browser->select('year', '2017');
However, if I try to use it with a for loop, it doesn't work
$years = ['2019', '2018', '2017'];
foreach ($years as $year) {
Log::info($year);
$browser->select('year', $year);
}
// logs 2019 and then crashes
(Facebook\WebDriver\Exception\StaleElementReferenceException(code: 0): stale element reference: element is not attached to the page document
I tried using waitFor(), pause(5000) or even waitForReload() but nothing has changed (except waitForReload crashed because it waited for 5 seconds without change)
I do not want the user to be logged out of the site even if the person is idle for, it is okay if the person is logged out if he has closed the browser.
session.gc_maxlifetime = 180000
session.gc_probability = 1
session.gc_divisor = 1
session.save_path = "/var/lib/php/session"
cookie_lifetime = 0
Is there any setting that i am missing?
Please help
To set the life time i have added the following code.
session_set_cookie_params(21600);
session_start();
You need extend your live time of cookie, remember that session id is stored in user webbrowser within cookie, set session.cookie_lifetime with a more big value too.
session_set_cookie_params(21600);
session_start();
21600 seconds is only 6 hours
Try setting to something bigger maybe even PHP_INT_MAX
Dont know whether it will help just wrote to give u the idea of how?....cookie are saved at user browser so ,
$cookieName = "userscookie";
$lifetime = time() + (60*60*24); // one day life
if(isset($_COOKIE[$cookieName])) {
$value = $_COOKIE[$cookieName];
// one day life from day of access
setcookie($cookieName, $value, $lifetime);
} else {
$value = "this value to store";
setcookie($cookieName, $value, $lifetime);
}
output:
Thankyou
I installed Laravel 4.0 and got this error
ErrorException
SessionHandler::read(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'
return (bool) $this->handler->close();
}
/**
* {#inheritdoc}
/
public function read($id)
{
return (string) $this->handler->read($id);
}
/*
Do you have Laravel 3 installed on the same machine? By default, Laravel 4 uses the same session cookie name (as Laravel 3), now found in /app/config/session.php file. Simply change:
'cookie' => 'laravel_session',
to, e.g.
'cookie' => 'laravel_session_4',
and refresh browser. All should work now.
It could be that you have a corrupt cookie. Try clearing cookies in your browser.
Take a look at this discussion: https://stackoverflow.com/a/16318456/1563189
Especially:
How do you end up with illegal characters in PHPSESSID in the first place? Aren't they generated by PHP automatically? – Lèse majesté Jul 6 '10 at 11:57
They are, but a cookie that links you to a generated session id is client side. If that cookie changes to an invalid format (somebody is trying to exploit something) PHP will notice it. – Aleksey Korzun Sep 6 '11 at 19:56
There is a bug report for this problem (https://bugs.php.net/bug.php?id=68063)
You can check the success of your session_start and generate the id if needed:
$ok = #session_start();
if(!$ok){
session_regenerate_id(true); // replace the Session ID
session_start();
}