具有参数的Laravel-4路由被调用两次 [英] Laravel-4 routes with parameters gets called twice

查看:102
本文介绍了具有参数的Laravel-4路由被调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我使用laravel开发的应用程序的激活路由发生奇怪的行为,经过数小时的xdebug等调试后,发现我的路由实际上有时被调用了两次.为了重现这种情况,我使用默认文件创建了一个新的laravel项目,并添加了一条简单的路由作为测试,该测试执行以下操作:

I noticed strange behaviour occuring for my activation route for an application that I'm developing using laravel and after hours of debugging through xdebug etc, it came into an observation that my route was actually called twice at times. To recreate the situation, I created a fresh new laravel project with default files and just added a simple route as a test that does the following:

Route::get('/activate/{code}', function($code)
{
   file_put_contents('/home/fa/testproj/route_called.txt', $code . "\n",   FILE_APPEND);
});

此简单路由基本上要做的是获取URI上传递的route参数并将其记录到文件中.奇怪的是,我注意到该路由对于在URI上键入的代码参数(例如http://myserver/activate/123456789)被调用了两次,但是对于重复的代码仅被调用了一次(可能是由于某些会话缓存吗?).多次尝试的"route_drawn.txt"文件的内容如下:

Basically what this simple route does is to take the route parameter passed on the URI and logs it into a file. Strangely, I noticed that the routes were called twice for code parameter that I typed on the URI (such as http://myserver/activate/123456789), but only once for repeated codes (probably due to some session caching?). The content of the 'route_called.txt' file for multiple tries was as follow:

123456789
123456789
123838384242
123838384242
123838384242        <---- notice that it's called only once for repeated parameter
1238383842424657347
1238383842424657347
332211576347
332211576347
332211576347    <---- notice that it's called only once for repeated parameter
1238376540897326
1238376540897326

laravel文件是最新的,除了上面的四行路由代码外,我没有做任何更改.我在公共文件夹中有laravel提供的标准文件:

The laravel files are fresh and I've not changed anything except for the four lines of route codes as above. I have standard files provided by laravel in the public folder:

-rw-rw-r-- 1 fa fa    0 Apr 15 16:06 favicon.ico
-rw-rw-r-- 1 fa fa  356 Apr 15 16:06 .htaccess
-rw-rw-r-- 1 fa fa 1586 Apr 15 16:06 index.php
drwxrwxr-x 2 fa fa 4096 Apr 15 16:06 packages/
-rw-rw-r-- 1 fa fa   24 Apr 15 16:06 robots.txt

laravel提供的.htaccess也未更改:

The .htaccess is untouched too as provided by laravel:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我的服务器是Ubuntu 12.04LTS,它运行Apache 2.2.22,并带有laravel所需的所有标准php模块.

My server is Ubuntu 12.04LTS, running Apache 2.2.22 with all the standard php modules required by laravel.

有人在其他地方说这可能是由于缺少favicon.ico问题引起的,但是laravel已经通过为我们提供上述的favicon.ico文件来解决了这个问题.

Some people say elsewhere that this could be due to missing favicon.ico issue but laravel has taken care of this problem by already providing us with the favicon.ico file as above.

我们非常感谢您的帮助.非常感谢!

Any help is much appreciated. Many thanks!

推荐答案

好吧,我设法找到了答案,为什么奇怪的行为是如此.与Laravel完全无关.似乎ISP级别的Internet筛选设备是将重复的HTTP请求发送到我的服务器的设备.我想设备会发送重复的请求来模仿我们的浏览页面请求,以便检查我们访问的网站是否符合过滤政策...必须重新设计我的应用程序的某些逻辑,以迎合这种情况.

Its ok folks, I managed to find the answer why the strange behaviour was so. It's nothing to do with Laravel at all. It seems that the internet filtering device at the ISP level was what sending the duplicate HTTP requests to my server. I guess the device would send duplicate requests mimicking our browsing page requests in order to check whether the sites that we visit complies with the filtering policies... Had to redesign some logics of my app in order to cater situations like this.

这篇关于具有参数的Laravel-4路由被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆