In my example setup, I have 2 directory (each is lumen 8.x project, created by running composer create-project --prefer-dist laravel/lumen lumenNUMBER
)
In my setup, webserver is apache/httpd with document root set to ~/www/
$router->get('/route1', function () use ($router) {
return "this is first route";
});
$router->get('/route2', function () use ($router) {
return "this is second route";
});
$router->get("/route5", ["uses"=>"CommonController@route5"] );
<?php
namespace App\Http\Controllers;
class CommonController extends Controller
{
public function route5() { "this is fifth route"; }
}
$router->get('/route1', function () use ($router) {
return "this is first route";
});
$router->get('/route2', function () use ($router) {
return "this is second route";
});
$router->get('/route3', function () use ($router) {
return "this is third route";
});
$router->get("/route4", ["uses"=>"SomeController@route4"] );
$router->get("/route5", ["uses"=>"CommonController@route5"] );
$router->get("/route6", ["uses"=>"CommonController@route6"] );
<?php
namespace App\Http\Controllers;
class CommonController extends Controller
{
public function route5() { "this is fifth route"; }
public function route6() { "this is sixth route"; }
}
<?php
namespace App\Http\Controllers;
class SomeController extends Controller
{
public function route4() { "this is fourth route"; }
}
Everything is running fine and good, I can make such request and get expected response:
For lumen1:
GET http://localhost/lumen1/public/route1
response this is first route
GET http://localhost/lumen1/public/route2
response this is second route
GET http://localhost/lumen1/public/route3
response error (expected): 404GET http://localhost/lumen1/public/route4
response error (expected): 404GET http://localhost/lumen1/public/route5
response this is fifth route
GET http://localhost/lumen1/public/route6
response error (expected): 404For lumen2:
GET http://localhost/lumen2/public/route1
response this is first route
GET http://localhost/lumen2/public/route2
response this is second route
GET http://localhost/lumen2/public/route3
response this is third route
GET http://localhost/lumen2/public/route4
response this is fourth route
GET http://localhost/lumen2/public/route5
response this is fifth route
GET http://localhost/lumen2/public/route6
response this is sixth route
But now I tried to get creative and deleted lumen2/vendor directory, then make symlink in lumen2/vendor to point to ../lumen1/vendor
ln -s ../lumen1/vendor vendor
lrwxrwxrwx 1 kristian kristian 16 Apr 21 08:49 vendor -> ../lumen1/vendor
The reason is that I'm low on disk space (this is not the only lumen project, I know it's only 40-50mb but the size is multiplied by number of project)
Now the request and their responses is (note that lumen1 is omitted since it's same with above):
GET http://localhost/lumen2/public/route1
response this is first route
GET http://localhost/lumen2/public/route2
response this is second route
GET http://localhost/lumen2/public/route3
response this is third route
GET http://localhost/lumen2/public/route4
response error (NOT expected): 500 Target class [App\Http\Controllers\SomeController] does not exist.GET http://localhost/lumen2/public/route5
response this is fifth route
GET http://localhost/lumen2/public/route6
response error (NOT expected): 404The question is:
I created 4 directory, each called a, b, c, d, each contains such php files:
view.php: <?php require_once("vendor/autoload.php"); echo "view-[x]";
vendor/autoload.php: <?php require_once(dirname( __FILE__ )."/../controller.php");
controller.php: <?php echo "app-[x]";
In which [x]
is replaced with directory name (so a/controller.php contains <?php echo "app-a";
, b/controller.php contains <?php echo "app-b";
, etc...)
directory a is the 'master'/'main'
directory b is copied from directory a cp -r a b
directory c is copied from directory a cp -r a c
, then I removed c/vendor and then softlink it from a's vendor directory: cd c; ln -s ../a/vendor vendor
directory d is copied from directory a cp -r a d
, then I removed d/vendor and then hardlink it from a's vendor directory: cp -al a/vendor d/vendor
I found out that output from:
GET http://localhost/a/view.php
is app-a view-a
GET http://localhost/b/view.php
is app-b view-b
GET http://localhost/c/view.php
is app-a view-c
GET http://localhost/d/view.php
is app-d view-d
This solves:
df -h
)As stated by NicoHaase in comment of my question, two separate application HAVE TO stay on two seperate vendor folders.
Yes, I know, I know this and I strongly agree. But in case it's not two separate applications. It's one application inside git repository that's made into multiple directory (via git worktree). And I have an ironclad rule that when I update one branch/worktree's composer.lock/composer.json (dependency), then I have to update the others. So the goal here is to save disk space.
Why don't I just use git's checkout command then? That's because I want to be able to simultaneously work on multiple branch at same time. Stashing and/or committing unfinished changes is out of the question.
Why bother about saving disk space? When you have this much free space you will try to save disk space:
$ # this is the size of my vendor directory
du -sh vendor
83M vendor
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 XXXX XXX 413M XXX /
$ rm -r vendor
$ # this is my free space when I deleted vendor directory
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 XXXX XXX 419M XXX /
$ cp -r ../../myproject/vendor/ vendor
$ # this is my free space when copied vendor directory
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 XXXX XXX 336M XXX /
$ cp -al ../myproject/vendor/ vendor
$ # this is my free space when using hardlinked vendor directory
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 XXXX XXX 413M XXX /
instead of ln -s [target] [link]
, do cp -al [target] [link]