Laravel 8 error vendor/symfony/polyfill-mbstring/Mbstring.php - php

i want to ask about the problem i'm having. I'm using 2 desktops i.e. ubuntu and mint, when I run my code on ubuntu it runs smoothly. but if i run on mint desktop i have an error that says "Symfony\Component\ErrorHandler\Error\FatalError
Maximum execution time of 60 seconds exceeded"
and i get this log on my terminal
Starting Laravel development server: http://127.0.0.1:8000
[Tue Nov 9 16:18:53 2021] PHP 8.0.12 Development Server (http://127.0.0.1:8000) started
[Tue Nov 9 16:18:55 2021] 127.0.0.1:38908 Accepted
[Tue Nov 9 16:18:55 2021] 127.0.0.1:38910 Accepted
[Tue Nov 9 16:20:22 2021] PHP Fatal error: Maximum execution time of 60 seconds exceeded in /home/aditya/Documents/Laravel/eyrin/vendor/symfony/polyfill-mbstring/Mbstring.php on line 632
[Tue Nov 9 16:20:23 2021] 127.0.0.1:38908 Closing
[Tue Nov 9 16:20:23 2021] 127.0.0.1:38910 Closed without sending a request; it was probably just an unused speculative preconnection
[Tue Nov 9 16:20:23 2021] 127.0.0.1:38910 Closing
and this is code on controller
$store = Store::where('user_id',Helper::getSession('user_id'))->first();
$match_report = [];
$top_weekly_product = [];
$compressed_date = [];
$uncompressed_date = Report::where('store_id',$store->id)->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->select('created_at')->distinct()->get();
foreach ($uncompressed_date as $item) {
if(!in_array(Carbon::parse($item['created_at'])->format('d/m/Y'),$match_report)){
$match_report[] = Carbon::parse($item['created_at'])->format('d/m/Y');
$compressed_date[] = $item;
}
}
$match_report = [];
$compressed_weekly_product = [];
$uncompressed_weekly_product = Report::where('store_id',$store->id)->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get()->map(function($report){
return [
'product_name'=>$report->product_name,
'product_variant'=>$report->product_variant,
'product_sku'=>$report->product_sku,
'weekly_amount'=>sizeof(Report::where(['store_id'=>$report->store_id, 'product_sku'=>$report->product_sku])->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get())
];
});
foreach ($uncompressed_weekly_product as $item) {
if(!in_array($item['product_sku'],$match_report)){
$match_report[] = $item['product_sku'];
$compressed_weekly_product[] = $item;
}
}
foreach ($compressed_weekly_product as $key => $item) {
$rows = [];
foreach ($compressed_date as $obj) {
$rows[] = sizeof(Report::where(['store_id'=>$store->id, 'product_sku'=>$item['product_sku']])->whereDate('created_at', Carbon::parse($obj['created_at']))->get());
}
$compressed_weekly_product[$key]['daily_amount'] = $rows;
}
foreach ($compressed_date as $key => $item) {
$compressed_date[$key]['formated'] = Carbon::parse($item->created_at)->format('m/d/Y');
}
$match_report = [];
usort($compressed_weekly_product, function($a, $b) {
return $a['weekly_amount'] > $b['weekly_amount'] ? -1 : 1;
});
foreach ($compressed_weekly_product as $item) {
if(sizeof($top_weekly_product) < 3){
$top_weekly_product[] = $item;
}
}
//testing
$growth_percentage = 1.8;
return view('panel.outlet.dashboard.index', [
'is_dashboard'=>true,
'total_customer'=>sizeof(Customer::where('store_id',$store->id)->get()),
'total_revenue'=>Order::where('store_id',$store->id)->whereIn('status',['2','3','-'])->sum('total_amount'),
'total_order'=>sizeof(Order::where('store_id',$store->id)->get()),
'total_sales'=>sizeof(Order::where('store_id',$store->id)->whereIn('status',['2','3','-'])->get()),
'total_product'=>sizeof(Product::where('store_id',$store->id)->get()),
'total_sales_income'=>Order::where('store_id',$store->id)->whereIn('status',['2','3','-'])->sum('total_amount'),
'growth_percentage'=>round($growth_percentage,2),
'lastest_order'=>Order::where(['store_id'=>$store->id,'type'=>'app'])->orderBy('id','DESC')->limit(10)->get(),
'report_date'=>$compressed_date,
'top_weekly_product'=>$top_weekly_product,
'weekly_product'=>$compressed_weekly_product,
'weekly_report'=>DailyReport::where('store_id',$store->id)->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get()]);
}
can anyone help me with this problem? i had a similar experience when i tried to truncrate a string in my blade view. does it have something to do with the configuration in my php.ini?
thankss i hope get solution for this problem...

This error appends when the max_execution_time of your PHP is reached. From the look of your error, it is probably set to 60 seconds.
You can increase this limit directly into your php.ini file (see with the command php --ini where it is located on your machine) or try to optimize your code.
If you don't want to edit the max_execution_time permanently, you can also add the instruction:
set_time_limit($seconds);
at the beginning of your script. I would not recommend this solution.

You can set it in the php.ini file in the max_execution_time variable, the default is 60 seconds, you can change it according to your needs

Symfony\Component\ErrorHandler\Error\FatalError
Maximum execution time of 60 seconds exceeded
There was a problem with the route. check your web.php
Route::get('feedback', 'App\Http\Controllers\FeedBackController#index')->name('feedback.index');
changed to
Route::get('cfeedback', 'App\Http\Controllers\FeedBackController#index')->name('feedback.index');
added only c in before feedback

I was having the same issue.
Running php via software collection the mbstring package was not installed.
# dnf install -y php73-php-mbstring
# systemctl restart php73-php-fpm
After installing packages and restarting service it was working well.

In your php.ini file, Uncomment extension=mbstring and you will see the error goes away.

Related

Laravel: Server crash on undefined array key

I was running a laravel server using php artisan serve --host <my-public-ip> --port 80 when suddenly my server crashed with this error:
Undefined array key 60196
at D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:263
259▕
260▕ $this->requestsPool[$requestPort][1] = trim(explode('[200]: GET', $line)[1]);
261▕ } elseif (str($line)->contains(' Closing')) {
262▕ $requestPort = $this->getRequestPortFromLine($line);
➜ 263▕ $request = $this->requestsPool[$requestPort];
264▕
265▕ [$startDate, $file] = $request;
266▕
267▕ $formattedStartedAt = $startDate->format('Y-m-d H:i:s');
1 D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php:263
Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("Undefined array key 60196", "D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Foundation\Console\ServeCommand.php")
2 D:\Code\schedule\bfcai-schedule\vendor\laravel\framework\src\Illuminate\Collections\Traits\EnumeratesValues.php:236
Illuminate\Foundation\Console\ServeCommand::Illuminate\Foundation\Console\{closure}("[Sat Feb 18 12:51:14 2023] 25.66.139.15:60196 Closing")
What may have caused this issue and what preventative measures can be taken to avoid its recurrence?
Have you tried debbuging the content of that array $this->requestsPool using die dump function such as
dd($this->requestPool);
Check if the key exist

Segfault in PHP without php error log. How to debug?

I have a script using com_dotnet, that makes PHP segfault (not sure if segfault is the technical correct term) under certain circumstances.
Using PHP 7.4.2 NTS 32bit on Windows 2019 64bit. The same error happens when using FCGI or CLI. The same script worked will with PHP 7.0.30.
In case of FCGI, only this error is in the Apache log:
[...] [fcgid:warn] [pid ...] (OS 109)The pipe has been ended. : [client ...] mod_fcgid: get overlap result error
[...] [fcgid:warn] [pid ...] (OS 109)The pipe has been ended. : [client ...] mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
In the event log, Application log, there is an Application Error event with id 1000:
Faulting application name: php-cgi.exe, version: 7.4.2.0, time stamp: 0x5e273bd1
Faulting module name: php7.dll, version: 7.4.2.0, time stamp: 0x5e274c52
Exception code: 0xc0000005
Fault offset: 0x004a1554
Faulting process id: 0x1d3c
Faulting application start time: 0x01d5e7035b9ba103
Faulting application path: F:\wamp\bin\php\php7.4.2nts86\php-cgi.exe
Faulting module path: F:\wamp\bin\php\php7.4.2nts86\php7.dll
Report Id: 83f813df-1bda-48f9-89f6-2374f9b04af5
Faulting package full name:
Faulting package-relative application ID:
And event 1001 Windows Error Reporting
Fault bucket 1785407568804712926, type 1
Event Name: APPCRASH
Response: Not available
Cab Id: 0
Problem signature:
P1: php-cgi.exe
P2: 7.4.2.0
P3: 5e273bd1
P4: php7.dll
P5: 7.4.2.0
P6: 5e274c52
P7: c0000005
P8: 004a1554
P9:
P10:
Attached files:
[Temp files no longer on disk]
These files may be available here:
\\?\C:\ProgramData\Microsoft\Windows\WER\ReportArchive\AppCrash_php-cgi.exe_db93fdd1eb9fce3ac32a6e96e418914fb9fca_32a55e52_0a30ae4b
Analysis symbol:
Rechecking for solution: 0
Report Id: 83f813df-1bda-48f9-89f6-2374f9b04af5
Report Status: 268435456
Hashed bucket: 85fc32c6322e070cd8c70ab96de611de
Cab Guid: 0
The WER\ReportArchive-file does not seem to contain interesting data.
I was not able to locate the exact place in the code where the fault is happening. It happens while reading data using the com_dotnet module.
if($this->statement->State == 1){
$result = [];
while(!$this->statement->EOF) {
$row = [];
for( $x = 0; $x < $this->statement->Fields->Count; $x++) {
$name = $this->statement->Fields[$x]->Name;
$value = $this->statement->Fields[$x]->Value;
$row[$name] = $value;
}
$this->statement->MoveNext();
$result[] = $row;
}
return $result;
}
The fault appears all tested data sources as soon as I read more than 9000 to 9500 rows. It does not seem to be related to the data itself.
The minimum code that leads to a fault is:
if($this->statement->State == 1){
$result = [];
while(!$this->statement->EOF) {
$row = [];
$row[] = ''; // <==
$this->statement->MoveNext();
$result[] = $row; // <==
}
return $result;
}
There is no fault when I remove either of the two lines marked with an arrow. Here the content of $result and the com-object are completely unrelated, and even so, PHP faults if there are more than 9000 loops. The number of lines leading to the fault does not seem to change neither with the data source, neither between the two code snippets above.
This here interestingly does not fault, even though $row = ['']; is functionally equivalent to $row = []; $row[] = ''; (above).
if($this->statement->State == 1){
$result = [];
while(!$this->statement->EOF) {
$row = [''];
$this->statement->MoveNext();
$result[] = $row;
}
return $result;
}
Here I'm at the end of my knowledge. Things do not seem to behave logically anymore. How could I narrow down the problem ? Any advice ?
Edit: PHP 7.3.15 is not affected, only PHP 7.4.2.

TYPO3 PHP Update to 7.0 | the logs say "Switch statements may only contain one default clause"

I want to update PHP from 5.6 to 7.0 but I get a 500 HTML Error and in the logs it says:
[Mon Oct 22 09:42:14 2018] [-:error] [pid 12784] [client 5.158.158.123] [host www.mydomain.de] PHP Fatal error: Switch statements may only contain one default clause in /is/htdocs/wp12731216_QEO0DONMD6/www/typo3conf/ext/dam/lib/class.tx_dam_db.php on line 547
So I looked into the file and found as it says a dublicate default: statement:
if ($appendType = $TCA['tx_dam']['columns'][$field]['config']['appendType']) {
$appended = true;
switch($appendType) {
case 'space':
$rowUpdate[$field] = trim($row[$field].' '.$value);
break;
case 'newline':
$rowUpdate[$field] = $row[$field].($row[$field]?"\n":'').$value;
break;
case 'comma':
$rowUpdate[$field] = $row[$field].($row[$field]?', ':'').$value;
break;
case 'charDef':
default:
list($type, $appendChar) = explode(':', $appendType);
$rowUpdate[$field] = $appendChar.$value;
break;
default:
$appended = false;
break;
}
}
So my Question is, is there a solution? Can I just edit this file and remove the last default statement? Or should I update to a different PHP Version?
So I found the solution myself after a while...
I had to update the Extension where the file with the error comes from.

php zend framework http client error

I am trying to write a piece of php code with zend framework. I`m using zend_http_client.The code works randomly!I mean , It works fine sometimes and sometimes get an empty page and this error from Apache error log :
[Mon May 27 16:46:37 2013] [error] [client 4.4.4.4] PHP Warning: require_once(/var/www/my.somesite.com/library/Zend/Http/Client/Adapter/Exception.php): failed to open stream: Too many open files in /var/www/my.somesite.com/library/Zend/Http/Client/Adapter/Socket.php on line 222
[Mon May 27 16:46:37 2013] [error] [client 4.4.4.4] PHP Fatal error: require_once(): Failed opening required 'Zend/Http/Client/Adapter/Exception.php' (include_path='/var/www/my.somesite.com/application/../library:../application/models:.:/usr/share/php:/usr/share/pear') in /var/www/my.somesite.com/library/Zend/Http/Client/Adapter/Socket.php on line 222
[Mon May 27 16:46:37 2013] [error] [client 4.4.4.4] PHP Fatal error: Undefined class constant 'PRIMARY_TYPE_NUM' in /var/www/my.somesite.com/library/Zend/Session/SaveHandler/DbTable.php on line 522
php code sth like this :
public function Request($server_method, $params_arr) {
$httpClient = new Zend_Http_Client;
$httpClient->setConfig(array('timeout' => '900'));
$client = new Zend_XmlRpc_Client ( Zend_Registry::getInstance ()->config->ibs->xmlrpc_url ,$httpClient);
$request = new Zend_XmlRpc_Request ( );
$response = new Zend_XmlRpc_Response ( );
$request->setMethod ( $server_method );
$request->setParams ( array ($params_arr ) );
$client->doRequest ( $request, $response );
if ($response->isFault ()) {
$fault = $response->getFault ();
//echo '<pre>' . $fault->getCode () . '' . $fault->getMessage () . '</pre>';
$this->response = array (FALSE, $fault->getMessage () );
return array (FALSE, $fault->getMessage () );
}
//return $response;
$this->response = array (TRUE, $response->getReturnValue () );
return array (TRUE, $response->getReturnValue () );
//var_dump($response->getReturnValue());
}
Where is the problem ?
The problem may be not related to your method itself.
You are opening many files and not closing them (a socket count as a file open too). The socket adapter itself has a configuration called persistent, set false to prevent TCP reuse.
Try to check if your http client is properly destroyed at end of use and is not refered in another place of your code (that prevents garbage collector cleaning).
More info:
Check the limits with ulimit -aH (max limit for number of open files)
There some numbers too in /etc/security/limits.conf
soft nofile 1024 <- Soft limit
hard nofile 65535 <- Hard limit
You could increase ulimit by ulimit -n 65535 and echo 65535 > /proc/sys/fs/file-max to set a higher value, but this is strongly discouraged.
To set this permamently, in /etc/sysctl.conf set fs.file-max=65535

Gettext works sometimes

I'm working on a project and I need to user translation for it. So I decided to use gettext in php but it's working sometimes.
So I have a folder named lng and in this on I have a php file who call my lang file to translate my page.
Here is the code :
<?php
if(isset($_GET['lang']) != '')
{
setcookie('lang',$_GET['lang'], time() + 365*24*3600, null, null, false, true);
$_SESSION['lang'] = $_GET['lang'];
$language = $_GET['lang'];
}
else if(isset($_SESSION['lang']) != '' )
{
$language = $_SESSION['lang'];
}
else if(isset($_COOKIE['lang']) != '')
{
$_SESSION['lang'] = $_COOKIE['lang'];
$language = $_SESSION['lang'];
}else{
$language = 'fr';
}
putenv("LANG=$language");
setlocale(LC_MESSAGES, $language);
$domain = 'trad';
bindtextdomain($domain, 'locale/');
textdomain($domain);
?>
So I can check my $_SESSION and $_COOKIE, no problem he give me 'en' or 'fr' but he doesn't translate my file and I don't know why.
For the folder in lng it's : locale/en/LC_MESSAGES/trad.po (or .mo).
I try with LC_ALL and LC_MESSAGES but that doesn't change the result.
Did I miss something or made a wrong stuff?
Thanks a lot!
J.
I've got the same problem. Restart Apache Service solved it for me
Aren't you using windows? If so, you must use windows locale names. Here is part of my class working for me on linux and also on windows (it simply has more options of locale names):
...
private function setLocaleByLang($lang)
{
$map = array(
'cs' => array('cs_CZ.UTF-8', 'cs_CZ', 'cs', 'czech'),
'en' => array('en_US.UTF-8', 'en_US', 'en', 'english'),
'de' => array('de_DE.UTF-8', 'de_DE', 'de', 'german'),
'pl' => array('pl_PL.UTF-8', 'pl_PL', 'pl', 'polish'),
'sk' => array('sk_SK.UTF-8', 'sk_SK', 'sk', 'slovak')
);
$locale = key_exists($lang, $map) ? $map[$lang] : $lang;
setlocale(LC_ALL, $locale);
putenv('LC_ALL=' . $lang); // for windows and gettext
}
...
I'm running into the same error. My case is a bit different, and I'm starting to think it has something to do with threading, despite it happens since I changed my code.
I have a language bar:
<?php
include_once (dirname(__FILE__) . "/resources/config.php");
?>
<div id='language_bar'>
<a style="margin-left:50px" href="./index.php?locale=es_ES">
<img src='<?php echo $config['paths']['images']['lang']?>/es_ES.gif'/>
</a>
<a href="./index.php?locale=en_UK">
<img src='<?php echo $config['paths']['images']['lang']?>/en_UK.gif'/>
</a>
<a href="./index.php?locale=de_DE">
<img src='<?php echo $config['paths']['images']['lang']?>/de_DE.gif'/>
</a>
</div>
And a config file with:
if (isset($_GET['locale'])) {
$locale = $_GET['locale'];
setcookie('locale', $locale, time() + 60 * 60 * 24 * 30);
} else {
if(isset($_COOKIE['locale'])) {
error_log('En _COOKIE');
$locale = $_COOKIE['locale'];
}
else {
$locale = $config['localization']['default_locale'];
setcookie('locale', $locale, time() + 60 * 60 * 24 * 30);
}
}
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
error_log('setlocale->'.setlocale(LC_ALL, "0")." Env ->". getenv("LC_ALL"));
error_log(_("Submit"));
My main page has some divs interacting via jQuery, and reloading in cascade. Sometimes, some of them (randomly) give a default string value.
by default, it is in spanish (es_ES), and after a few clicks forcing div refreshes, some string is printed in english (en_UK original string). And what is more. If I switch to german (de_DE), after a first refresh where I get every string in german, gettext starts to reurn strings in spanish, and after a while, in english.
Note that I added debug lines to php log. They are really interesting:
When things go right:
[Thu May 31 00:28:51 2012] [error] [client ::1] setlocale->es_ES Env ->es_ES
[Thu May 31 00:28:51 2012] [error] [client ::1] Aplicar, referer: xxxxxxxx/index.php
When do not:
[Thu May 31 00:29:45 2012] [error] [client ::1] setlocale->es_ES Env ->es_ES, referer: xxxxxxxxx/index.php
[Thu May 31 00:29:45 2012] [error] [client ::1] Submit, referer: xxxxxxxx/index.php
So I guess it's _() function failing (I'm always using the alias). Just in case, I looped for 10.000 times over the function, and it gave or 10.000 hits or 10.000 mistakes while translating, so it fails for a whole http request, or doesn't.
My apologies for writing so much, but I would really appreciate some help pointing me in the right direction. (This error occurs not just # my localhost, but also at my online test server)
¿might have anything to do with the fact that I'm setting the locale for every connection?
My online "playground" is:
Linux server8.nixiweb.com 2.6.32-71.29.1.el6.x86_64 #1 SMP Mon Jun 27 19:49:27 BST 2011 x86_64
My server:
Linux filete 3.2.0-24-generic #39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012 x86_64
PHP Version 5.3.10-1ubuntu3.1
Note that both are 64bits
I had the same problem. Sometimes the strings were translated and sometimes don't. I have 3 servers for this application and 5 developers' machines, all with the same problem.
I solve it by removing:
bindtextdomain("domain", "/locale");
And linking the .mo file directly on the gettext default folder:
sudo ln -sf /myproject/locale/en/LC_MESSAGES/domain.mo /usr/share/locale/en/LC_MESSAGES/domain.mo
I am using Ubuntu 14.04.

Categories