laravel 各种错误

今天系统又再次出现了:
    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'),

猜你喜欢

转载自blog.csdn.net/beyond__devil/article/details/82621280