Event::listen('illuminate.query', function($sql, $param,$time){ // $tmp = str_replace('?', '"'.'%s'.'"', $sql); // $data=[]; // $tmp = 'desc '.str_replace(array('%', '?'), array('%%', '"%s"'), $sql).';'; // // // if(strpos($sql,'update ') !== false || strpos($sql,'delete ') !== false){ // // if (!file_exists(storage_path().'/logs/sqls/'.date('Y-m'))) // // mkdir(storage_path().'/logs/sqls/'.date('Y-m')); // // if(Auth::check()){ // // $person = Auth::user()->name; // // } // // file_put_contents(storage_path().'/logs/sqls/'.date('Y-m').'/'.date('Y-m-d').'.log','[ '.date('Y-m-d H:i:s').' ] '.vsprintf($tmp, $param).(empty($person)?'':'操作人:'.$person)."\r\n",8); // // } // // // if (!file_exists(storage_path().'/logs/sqls')){ mkdir (storage_path().'/logs/sqls');} // // if (!file_exists(storage_path().'/logs/sqls/'.date('Y-m-d'))){ mkdir (storage_path().'/logs/sqls/'.date('Y-m-d'));} // // file_put_contents(storage_path().'/logs/sqls/'.date('Y-m-d').'/'.str_replace('/','^',str_replace('http://','',Request::url())).'.log','[ '.date('Y-m-d H:i:s').' ] '.vsprintf($tmp, $param)."\r\n",8); // // print $time; // if($time > 1500) // { // if(strpos($sql,'select ') !== false ){ // $data=[ // 'sql'=>vsprintf($tmp, $param), // 'time'=>$time/1000, // 'url'=>Request::url(), // ]; // // dump($data); // DB::table('log_sql')->insert($data); // Mail::send('emails.indexes',['data'=>$data],function($message){ // $to = 'ouzhibi@258.com'; // $message ->to($to)->subject('您有新的数据索引需要优化'); // }); // } // } //// Log::info($sql . ", with[" . join(',', $param) ."]"); });
宠物免费领养小程序,欢迎来踩