Valet: Valet runs twice on BasicValetDriver

Created on 16 Apr 2018  路  6Comments  路  Source: laravel/valet

Created a basic php file with a so simple code below on an empty folder in my sites folder

<?php
exec('touch ' . rand(1,100));
?>

when I visit the folder from browser like foldername.test, this php code generates two different file in working directory. I also test it with a simple PDO code that inserts only one row into table however it inserts two rows.

Most helpful comment

Hej,

nope - this isn't a bug in valet. there is a simple way to reproduce it.

step 1: create an index.php file with the following content:

<?php
exec('touch ' . rand(1,100));

now your directory should look like this

 ~/Code/test 禄 ls -la
total 8
drwxr-xr-x   3 jw  staff   96 Dec 22 21:46 .
drwxr-xr-x  19 jw  staff  608 Dec 22 21:30 ..
-rw-r--r--   1 jw  staff   39 Dec 22 21:30 index.php

step 2: create a domain and optional create an ssl cert
valet link --secure

step 3: open the path in browser with the command valet open

step 4: list code directory. there sould be a random file now

~/Code/test 禄 ls -la
total 8
drwxr-xr-x   4 jw  staff  128 Dec 22 21:47 .
drwxr-xr-x  19 jw  staff  608 Dec 22 21:30 ..
-rw-r--r--   1 jw  staff    0 Dec 22 21:47 51
-rw-r--r--   1 jw  staff   39 Dec 22 21:30 index.php

step 5: delete the new file

step 6: open safari browser and insert the URL to your test environment, but do not press enter.

step 7: list directory again

~/Code/test 禄 ls -ltrah
total 8
drwxr-xr-x  19 jw  staff   608B Dec 22 21:30 ..
-rw-r--r--   1 jw  staff    39B Dec 22 21:30 index.php
-rw-r--r--   1 jw  staff     0B Dec 22 21:51 22
drwxr-xr-x   4 jw  staff   128B Dec 22 21:51 .

step 8: press enter, there should be another random file.

I my opinion there is a preloading of websites in modern browsers. That is the reason for two random files, which is mentioned by @XEngine in the first post.

there is no error in valet.

cheers

All 6 comments

Hey XEngine, I've got the same problem, did you figure out what the cause was?

Hello @indexsmithy, Currently I found no solution but I am now using Valet plus instead of valet, however didn't test this bug on that. https://github.com/weprovide/valet-plus

I run into the same issue. I created a simple project:
{ "require": { "illuminate/database": "^5.7" } }
i put my index.php in the root, and ran valet link, loaded up php file in valet url.
The php was processed twice, as i got 2 inserts.
Subsequently running same code on built in php server it ran only once.
I created a public folder, moved the index.php to it, valet unlinked the root folder.
Ran valet link inside the public folder. browsed to it. no more duplicate inserts!

Addendum: I valet unlinked the public folder, deleted public, moved index.php back to root.
Then created a LocalValetDriver.php which extended LaravelValetDriver, and added this:
public function frontControllerPath($sitePath, $siteName, $uri) { return $sitePath.'/index.php'; }
Valet link again in the root, this time it worked, only 1 insert.

Hej,

nope - this isn't a bug in valet. there is a simple way to reproduce it.

step 1: create an index.php file with the following content:

<?php
exec('touch ' . rand(1,100));

now your directory should look like this

 ~/Code/test 禄 ls -la
total 8
drwxr-xr-x   3 jw  staff   96 Dec 22 21:46 .
drwxr-xr-x  19 jw  staff  608 Dec 22 21:30 ..
-rw-r--r--   1 jw  staff   39 Dec 22 21:30 index.php

step 2: create a domain and optional create an ssl cert
valet link --secure

step 3: open the path in browser with the command valet open

step 4: list code directory. there sould be a random file now

~/Code/test 禄 ls -la
total 8
drwxr-xr-x   4 jw  staff  128 Dec 22 21:47 .
drwxr-xr-x  19 jw  staff  608 Dec 22 21:30 ..
-rw-r--r--   1 jw  staff    0 Dec 22 21:47 51
-rw-r--r--   1 jw  staff   39 Dec 22 21:30 index.php

step 5: delete the new file

step 6: open safari browser and insert the URL to your test environment, but do not press enter.

step 7: list directory again

~/Code/test 禄 ls -ltrah
total 8
drwxr-xr-x  19 jw  staff   608B Dec 22 21:30 ..
-rw-r--r--   1 jw  staff    39B Dec 22 21:30 index.php
-rw-r--r--   1 jw  staff     0B Dec 22 21:51 22
drwxr-xr-x   4 jw  staff   128B Dec 22 21:51 .

step 8: press enter, there should be another random file.

I my opinion there is a preloading of websites in modern browsers. That is the reason for two random files, which is mentioned by @XEngine in the first post.

there is no error in valet.

cheers

Yes, this is my understanding of the situation as well.

@mattstauffer I think this can be closed.

Great sleuthing!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hsleewis picture hsleewis  路  5Comments

EHLOVader picture EHLOVader  路  4Comments

dannygsmith picture dannygsmith  路  5Comments

sadhakbj picture sadhakbj  路  3Comments

webartistse picture webartistse  路  4Comments