laravel 各種錯誤
阿新 • • 發佈:2018-11-06
今天系統又再次出現了: Fatal error: Uncaught ReflectionException: Class log does not exist in /private/var/www/pinxuejianyou/vendor/laravel/framework/src/Illuminate/Container/Container.php:734 居然完全想不起來之前已經記錄過相同的錯誤了!網上查了半天,看著怎麼感覺越看越好像看過這些答案。。。印象中,也寫過這麼一篇總結,最後找到了,就是這個問題。 現在放到部落格上來,人這記性無語了。。。 1. 問題: Please provide a valid cache path 解決方法: 1、確保storage目錄下有如app,framework,views三個目錄。 2、確保storage/framework目錄下也有cache,sessions,views三個目錄。 提示: 儘量不要手動建立,有 .gitignore,直接從github,或其他laravel專案複製一份 2. 問題: Class cache does not exist 解決方法: 不知道為什麼,好好的出現了這個問題。可能是服務突然不正常了... google搜尋,看到有2個答案: 1>May be you used url() helper in your any config file like below code, check it out and remove it.. url('bassets/plugins/highcharts/highcharts.css') 2>In my case (laravel 5.2) the issue was in custom service provider, where I declared custom response macroses in register() instead of boot() function. After moving macroses to the boot() the error disappeared 解決方法:https://laracasts.com/discuss/channels/laravel/class-cache-does-not-exist-error-when-use-redis-session-file-session-is-fine 但是,我的真不是這些問題,nginx 和 redis 都重啟了,都沒反應。看國外的,定義了一個: HelperServiceProvider.php,用於自動載入各種檔案: class HelperServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { // } /** * Register any application services. * * @return void */ public function register() { foreach(glob(app_path() . '/Helpers/*.php') as $filename){ require_once($filename); } } } 我的其中一個配置檔案,使用了 'url()' 方法,但是我列印,是可以出來的! 不知道為什麼! 終極解決方案(不知道究竟為什麼報錯!): 重啟了電腦,依舊報錯!! 直接刪除 storage/* 從其他laravel中,複製 storage/* 就OK了! 3. 問題: Fatal error: Uncaught ReflectionException: Class log does not exist in /private/var/www/pinxuejianyou/vendor/laravel/framework/src/Illuminate/Container/Container.php:734 解決方法: 更完整的問題分析,在部落格的這篇文章: http://blog.csdn.net/beyond__devil/article/details/78269074 這個問題可謂是各種坑啊!!!和 'log' 有什麼關係!!找了好多,有一篇文章總結的很有道理! https://stackoverflow.com/questions/34978828/uncaught-reflectionexception-class-log-does-not-exist-laravel-5-2 複製作者發現問題: /* Okay, after many hours of digging, the solution for my problem has been found. The reason why I say my problem is because the Exception is very mis-leading. Uncaught ReflectionException: Class log does not exist This exception simply means Laravel tried to log an error but couldn't instantiate Laravel's Log class. This is not due to the Log class going walk-abouts or hiding. This is because Laravel is still going through its boot process & has yet to load the Log class. So, this exception is thrown because an error occurred during the boot cycle of Laravel - when this error occurred it tried to throw an exception - but it can't throw an exception because the Log class is yet the be loaded. Hence the reason we get a ReflectionException This has occurred in all versions of Laravel the only reason we have seen the exception thrown in laravel 5.1 <= is because previously Laravel silently discarded the problem & carried on through its boot process - basically, your app would still break however you would not receive the Log class exception. In my particular case I didn't have the php-mysql extension installed causing Laravel to break during its boot process. Ultimately, it is incredibly difficult to debug what you may have done wrong due to the error been very mis-leading. I hope this helps someone! */ 和我的這個問題,並不一樣,但是裡面提到的 "本質原因" 應該正確!這個異常的原因是: laravel發現一個錯誤,並嘗試使用 log 記錄這個錯誤,但是還並未例項化log類。是因為,laravel還在啟動過程中,還並未載入log類。 是什麼導致錯誤的!這個問題比較難找!(正如上面說的,作者自己都找了好幾個小時!)我也是對比了這個修改的檔案版本,回退到上個版本,沒有問題!然後一個個檔案排查!! 尤其是: http訪問下,沒問題,就是 console下有問題!! 最後,排查到是:url() 這個函式的問題! 思考了下,console下,自然是不會引入 Request、URL這類擴充套件,所以 url() 這裡導致了錯誤! 再次搜尋: laravel下,如何區分是在 http 還是 console 核心? http://laravel-recipes.com/recipes/2/checking-if-youre-running-in-the-console laravel是給我們提供了這個方法的 App::runningInConsole() 其實就是使用PHP函式 php_sapi_name() 進行的判斷! php高版本,估計已經統一成了 'cli',之前還有各種 apache2handler, cgi等等,可檢視該函式詳細瞭解! 最終解決方案: $options['url']' = (php_sapi_name() == 'cli') ? '' : url('/test'),