可能是下面说的这个问题么
你这个基本属于能必现的问题 理论上用二分法很快能定位问题的
https://bugs.php.net/bug.php?id=76436 [2019-08-14 21:50 UTC] phpbug at ethaniel dot com
I have this problem in PHP 5.6.40 on Centos 7.6.
This simple code triggers it. I just read around 1 million rows from the table and my memory usage is just growing higher and higher.
$cnt = 0;
$result = mysqli_query($conn,"SELECT `text`,`sms_date`,`to` FROM `sms_data`.`sms_201933`;");
while ($row = mysqli_fetch_object($result)) {
if ($cnt%1000) {
echo memory_get_usage()." *** \n\n";
}
$cnt++;
}
// 不同主题的配置最好分开
$themeAllTabs = [
'default' => [
'index' => [
'pagePath' => '/pages/index/index',
'text' => '首页',
'iconPath' => '/assets/images/home_unactived.png',
'selectedIconPath' => '/assets/images/home_actived.png',
],
'cart' => [
'pagePath' => '/pages/cart/cart',
'text' => '购物车',
'iconPath' => '/assets/images/cart_unactived.png',
'selectedIconPath' => '/assets/images/cart_actived.png',
],
'mine' => [
'pagePath' => '/pages/mine/mine',
'text' => '我的',
'iconPath' => '/assets/images/mine_unactived.png',
'selectedIconPath' => '/assets/images/mine_actived.png',
]
],
1 => [
'index' => [
'pagePath' => '/pages/index/index',
'text' => '首页',
'iconPath' => '/assets/images/home_unactived.png',
'selectedIconPath' => '/assets/images/theme1_home_actived.png',
],
'collection' => [
"pagePath" => "/pages/collection/collection",
"iconPath" => "/assets/images/collection.png",
"selectedIconPath" => "/assets/images/collection_actived.png",
"text" => "收藏"
],
'bestforyou' => [
"pagePath" => "/pages/bestforyou/bestforyou",
"iconPath" => "/assets/images/bestforyou_unactived.png",
"selectedIconPath" => "/assets/images/bestforyou_actived.png",
"text" => "为你优选"
],
'cart' => [
'pagePath' => '/pages/cart/cart',
'text' => '购物车',
'iconPath' => '/assets/images/cart_unactived.png',
'selectedIconPath' => '/assets/images/cart_actived.png',
],
'mine' => [
'pagePath' => '/pages/mine/mine',
'text' => '我的',
'iconPath' => '/assets/images/mine_unactived.png',
'selectedIconPath' => '/assets/images/mine_actived.png',
]
]
];
$themeDisplayTabs = [
'default' => [
'index',
'mine'
],
1 => [
'index',
'collection',
'bestforyou',
'mine'
]
];
$themePluginActions = [
'default' => [
'PG_SHOPPING_CART' => function($tabs) {
array_splice( $tabs, 1, 0, 'cart');
return $tabs;
}
],
'1' => [
'PG_SHOPPING_CART' => function($tabs) {
array_splice($tabs, 3, 0, 'cart');
return $tabs;
}
]
];
$theme = $config['theme'] == 1 ? 1 : 'default';
$tabNames = $themeDisplayTabs[$theme];
foreach($config['plugin'] as $plugName => $available) {
$plugAction = $themePluginActions[$theme][$plugName] ?? null;
if ($available && $plugAction != null) {
$tabNames = $plugAction($tabNames);
}
}
$tabIndex = array_flip($tabNames);
$tablist = array_map(function ($tabName) use ($theme, $themeAllTabs) {
return $themeAllTabs[$theme][$tabName];
}, $tabNames);
静态的看待这个问题,同事的代码是有点啰嗦
但是事情发展一般都是动态的
[
'pagePath' => '/pages/mine/mine',
'text' => '我的',
'iconPath' => '/assets/images/mine_unactived.png',
'selectedIconPath' => '/assets/images/mine_actived.png',
]
要不要把这个抽出来封装这个事情还真不好说 也许只是恰好各种条件都是这样的 没有更多的上下文条件不好定论
等楼主见过运行了 5678 年,换过 345 波人的项目代码,肯定会觉得现在同事的代码好像也不算非常糟糕了