5
5
use Illuminate \Console \Command ;
6
6
use Illuminate \Support \Carbon ;
7
7
use Illuminate \Support \Env ;
8
+ use Illuminate \Support \InteractsWithTime ;
8
9
use Symfony \Component \Console \Attribute \AsCommand ;
9
10
use Symfony \Component \Console \Input \InputOption ;
10
11
use Symfony \Component \Process \PhpExecutableFinder ;
15
16
#[AsCommand(name: 'serve ' )]
16
17
class ServeCommand extends Command
17
18
{
19
+ use InteractsWithTime;
20
+
18
21
/**
19
22
* The console command name.
20
23
*
@@ -88,14 +91,14 @@ class ServeCommand extends Command
88
91
public function handle ()
89
92
{
90
93
$ environmentFile = $ this ->option ('env ' )
91
- ? base_path ('.env ' ).'. ' .$ this ->option ('env ' )
92
- : base_path ('.env ' );
94
+ ? base_path ('.env ' ).'. ' .$ this ->option ('env ' )
95
+ : base_path ('.env ' );
93
96
94
97
$ hasEnvironment = file_exists ($ environmentFile );
95
98
96
99
$ environmentLastModified = $ hasEnvironment
97
- ? filemtime ($ environmentFile )
98
- : now ()->addDays (30 )->getTimestamp ();
100
+ ? filemtime ($ environmentFile )
101
+ : now ()->addDays (30 )->getTimestamp ();
99
102
100
103
$ process = $ this ->startProcess ($ hasEnvironment );
101
104
@@ -242,7 +245,7 @@ protected function getHostAndPort()
242
245
protected function canTryAnotherPort ()
243
246
{
244
247
return is_null ($ this ->input ->getOption ('port ' )) &&
245
- ($ this ->input ->getOption ('tries ' ) > $ this ->portOffset );
248
+ ($ this ->input ->getOption ('tries ' ) > $ this ->portOffset );
246
249
}
247
250
248
251
/**
@@ -292,23 +295,29 @@ protected function flushOutputBuffer()
292
295
293
296
$ this ->requestsPool [$ requestPort ] = [
294
297
$ this ->getDateFromLine ($ line ),
295
- false ,
298
+ $ this ->requestsPool [$ requestPort ][1 ] ?? false ,
299
+ microtime (true ),
296
300
];
297
301
} elseif (str ($ line )->contains ([' [200]: GET ' ])) {
298
302
$ requestPort = $ this ->getRequestPortFromLine ($ line );
299
303
300
304
$ this ->requestsPool [$ requestPort ][1 ] = trim (explode ('[200]: GET ' , $ line )[1 ]);
305
+ } elseif (str ($ line )->contains ('URI: ' )) {
306
+ $ requestPort = $ this ->getRequestPortFromLine ($ line );
307
+
308
+ $ this ->requestsPool [$ requestPort ][1 ] = trim (explode ('URI: ' , $ line )[1 ]);
301
309
} elseif (str ($ line )->contains (' Closing ' )) {
302
310
$ requestPort = $ this ->getRequestPortFromLine ($ line );
303
311
304
312
if (empty ($ this ->requestsPool [$ requestPort ])) {
305
313
$ this ->requestsPool [$ requestPort ] = [
306
314
$ this ->getDateFromLine ($ line ),
307
315
false ,
316
+ microtime (true ),
308
317
];
309
318
}
310
319
311
- [$ startDate , $ file ] = $ this ->requestsPool [$ requestPort ];
320
+ [$ startDate , $ file, $ startMicrotime ] = $ this ->requestsPool [$ requestPort ];
312
321
313
322
$ formattedStartedAt = $ startDate ->format ('Y-m-d H:i:s ' );
314
323
@@ -318,7 +327,7 @@ protected function flushOutputBuffer()
318
327
319
328
$ this ->output ->write (" <fg=gray> $ date</> $ time " );
320
329
321
- $ runTime = $ this ->getDateFromLine ( $ line )-> diffInSeconds ( $ startDate );
330
+ $ runTime = $ this ->runTimeForHumans ( $ startMicrotime );
322
331
323
332
if ($ file ) {
324
333
$ this ->output ->write ($ file = " $ file " );
@@ -327,7 +336,7 @@ protected function flushOutputBuffer()
327
336
$ dots = max (terminal ()->width () - mb_strlen ($ formattedStartedAt ) - mb_strlen ($ file ) - mb_strlen ($ runTime ) - 9 , 0 );
328
337
329
338
$ this ->output ->write (' ' .str_repeat ('<fg=gray>.</> ' , $ dots ));
330
- $ this ->output ->writeln (" <fg=gray>~ {$ runTime }s </> " );
339
+ $ this ->output ->writeln (" <fg=gray>~ {$ runTime }</> " );
331
340
} elseif (str ($ line )->contains (['Closed without sending a request ' , 'Failed to poll event ' ])) {
332
341
// ...
333
342
} elseif (! empty ($ line )) {
0 commit comments