f4i2u1 f4i2u1 - 2 months ago 14
PHP Question

Laravel-4 routes with parameters gets called twice

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);

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
), 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:

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

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

The .htaccess is untouched too as provided by laravel:

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

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]

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

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!


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.