@@ -95,10 +95,11 @@ function print_help()
95
95
option can be provided multiple times.
96
96
--install-dir <path> Install to a specific directory. Default: ' $ installdir'
97
97
--uninstall Uninstall the library from the specified binaries.
98
+ --file <path to .tar.gz> Path to a dd-library-php-*.tar.gz file. Can be used for offline installation.
98
99
--extension-dir <path> Specify the extension directory. Default: PHP's extension directory.
99
100
--ini <path> Specify the INI file to use. Default: <ini-dir>/98-ddtrace.ini
100
101
--enable-appsec Enable the application security monitoring module.
101
- --enable-profiling Enable the profiling module.
102
+ --enable-profiling Enable the profiling module.
102
103
-d setting[=value] Used in conjunction with `config <set|get>`
103
104
command to specify the INI setting to get or set.
104
105
@@ -462,9 +463,58 @@ function install($options)
462
463
$ selectedBinaries = require_binaries_or_exit ($ options );
463
464
$ interactive = empty ($ options [OPT_PHP_BIN ]);
464
465
466
+ $ commandExtensionSuffixes = [];
467
+ $ downloadVersions = [];
468
+ foreach ($ selectedBinaries as $ command => $ fullPath ) {
469
+ $ binaryForLog = ($ command === $ fullPath ) ? $ fullPath : "$ command ( $ fullPath) " ;
470
+ echo "Checking for binary: $ binaryForLog \n" ;
471
+
472
+ check_php_ext_prerequisite_or_exit ($ fullPath , 'json ' );
473
+
474
+ $ phpProperties = ini_values ($ fullPath );
475
+ if (!isset ($ phpProperties [INI_SCANDIR ])) {
476
+ if (!isset ($ phpProperties [INI_MAIN ])) {
477
+ if (IS_WINDOWS ) {
478
+ $ phpProperties [INI_MAIN ] = dirname ($ fullPath ) . "/php.ini " ;
479
+ } else {
480
+ print_error_and_exit (
481
+ "It is not possible to perform installation on this "
482
+ . "system because there is no scan directory and no "
483
+ . "configuration file loaded. "
484
+ );
485
+ }
486
+ }
487
+
488
+ print_warning (
489
+ "Performing an installation without a scan directory may "
490
+ . "result in fragile installations that are broken by normal "
491
+ . "system upgrades. It is advisable to use the configure "
492
+ . "switch --with-config-file-scan-dir when building PHP. "
493
+ );
494
+ }
495
+
496
+ // Suffix (zts/debug)
497
+ $ extensionSuffix = '' ;
498
+ if (is_truthy ($ phpProperties [IS_DEBUG ])) {
499
+ $ extensionSuffix .= '-debug ' ;
500
+ }
501
+ if (is_truthy ($ phpProperties [THREAD_SAFETY ])) {
502
+ $ extensionSuffix .= '-zts ' ;
503
+ }
504
+
505
+ $ commandExtensionSuffixes [$ command ] = $ extensionSuffix ;
506
+
507
+ $ extensionVersion = $ phpProperties [PHP_API ];
508
+ $ downloadVersions ["$ extensionVersion$ extensionSuffix " ] = true ;
509
+ }
510
+
511
+ $ tar_gz_suffix = "" ;
512
+ if (count ($ downloadVersions ) === 1 ) {
513
+ $ tar_gz_suffix = "- " . key ($ downloadVersions );
514
+ }
515
+
465
516
// Preparing clean tmp folder to extract files
466
517
$ tmpDir = sys_get_temp_dir () . '/dd-install ' ;
467
- $ tmpDirTarGz = $ tmpDir . "/dd-library-php- {$ platform }.tar.gz " ;
468
518
$ tmpArchiveRoot = $ tmpDir . '/dd-library-php ' ;
469
519
$ tmpArchiveTraceRoot = $ tmpDir . '/dd-library-php/trace ' ;
470
520
$ tmpArchiveAppsecRoot = $ tmpDir . '/dd-library-php/appsec ' ;
@@ -490,8 +540,14 @@ function install($options)
490
540
print_warning ('-- ' . OPT_FILE . ' option is intended for internal usage and can be removed without notice ' );
491
541
$ tmpDirTarGz = $ options [OPT_FILE ];
492
542
} else {
493
- $ url = RELEASE_URL_PREFIX . "dd-library-php- " . RELEASE_VERSION . "- {$ platform }.tar.gz " ;
494
- download ($ url , $ tmpDirTarGz );
543
+ for (;;) {
544
+ $ url = RELEASE_URL_PREFIX . "dd-library-php- " . RELEASE_VERSION . "- {$ platform }{$ tar_gz_suffix }.tar.gz " ;
545
+ $ tmpDirTarGz = $ tmpDir . "/dd-library-php- {$ platform }{$ tar_gz_suffix }.tar.gz " ;
546
+ if (download ($ url , $ tmpDirTarGz , $ tar_gz_suffix != "" )) {
547
+ break ;
548
+ }
549
+ $ tar_gz_suffix = "" ; // retry with the full archive if the original download failed
550
+ }
495
551
}
496
552
if (!IS_WINDOWS || `where tar 2> nul ` !== null ) {
497
553
execute_or_exit (
@@ -574,15 +630,7 @@ function install($options)
574
630
575
631
// Copying the extension
576
632
$ extensionVersion = $ phpProperties [PHP_API ];
577
-
578
- // Suffix (zts/debug/alpine)
579
- $ extensionSuffix = '' ;
580
- if (is_truthy ($ phpProperties [IS_DEBUG ])) {
581
- $ extensionSuffix .= '-debug ' ;
582
- }
583
- if (is_truthy ($ phpProperties [THREAD_SAFETY ])) {
584
- $ extensionSuffix .= '-zts ' ;
585
- }
633
+ $ extensionSuffix = $ commandExtensionSuffixes [$ command ];
586
634
587
635
$ extDir = isset ($ options [OPT_EXTENSION_DIR ]) ? $ options [OPT_EXTENSION_DIR ] : $ phpProperties [EXTENSION_DIR ];
588
636
echo "Installing extension to $ extDir \n" ;
@@ -1416,7 +1464,7 @@ function execute_or_exit($exitMessage, $command)
1416
1464
* @param string $url
1417
1465
* @param string $destination
1418
1466
*/
1419
- function download ($ url , $ destination )
1467
+ function download ($ url , $ destination, $ retry = false )
1420
1468
{
1421
1469
echo "Downloading installable archive from $ url. \n" ;
1422
1470
echo "This operation might take a while. \n" ;
@@ -1444,12 +1492,20 @@ function download($url, $destination)
1444
1492
curl_setopt ($ ch , CURLOPT_NOPROGRESS , false );
1445
1493
$ progress_counter = 0 ;
1446
1494
$ return = curl_exec ($ ch );
1495
+
1496
+ if ($ retry ) {
1497
+ $ httpCode = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
1498
+ if ($ httpCode == 404 ) {
1499
+ return false ;
1500
+ }
1501
+ }
1502
+
1447
1503
curl_close ($ ch );
1448
1504
fclose ($ fp );
1449
1505
1450
1506
if (false !== $ return ) {
1451
1507
echo $ okMessage ;
1452
- return ;
1508
+ return true ;
1453
1509
}
1454
1510
// Otherwise we attempt other methods
1455
1511
}
@@ -1461,20 +1517,20 @@ function download($url, $destination)
1461
1517
if (!IS_WINDOWS && false !== exec ('curl --version ' , $ output , $ statusCode ) && $ statusCode === 0 ) {
1462
1518
$ curlInvocationStatusCode = 0 ;
1463
1519
system (
1464
- 'curl -L --output ' . escapeshellarg ($ destination ) . ' ' . escapeshellarg ($ url ),
1520
+ 'curl -f - L --output ' . escapeshellarg ($ destination ) . ' ' . escapeshellarg ($ url ),
1465
1521
$ curlInvocationStatusCode
1466
1522
);
1467
1523
1468
1524
if ($ curlInvocationStatusCode === 0 ) {
1469
1525
echo $ okMessage ;
1470
- return ;
1526
+ return true ;
1471
1527
}
1472
1528
// Otherwise we attempt other methods
1473
1529
}
1474
1530
1475
1531
// file_get_contents
1476
1532
if (is_truthy (ini_get ('allow_url_fopen ' )) && extension_loaded ('openssl ' )) {
1477
- ini_set ("memory_limit " , "1G " ); // increase memory limit otherwise we may run OOM here.
1533
+ ini_set ("memory_limit " , "2G " ); // increase memory limit otherwise we may run OOM here.
1478
1534
$ data = @file_get_contents ($ url );
1479
1535
// PHP doesn't like too long location headers, and on PHP 7.3 and older they weren't read at all.
1480
1536
// But this only really matters for CircleCI artifacts, so not too bad.
@@ -1491,11 +1547,14 @@ function download($url, $destination)
1491
1547
}
1492
1548
got_data: ;
1493
1549
if ($ data == "" || false === file_put_contents ($ destination , $ data )) {
1550
+ if ($ retry ) {
1551
+ return false ;
1552
+ }
1494
1553
print_error_and_exit ("Error while downloading the installable archive from $ url \n" );
1495
1554
}
1496
1555
1497
1556
echo $ okMessage ;
1498
- return ;
1557
+ return true ;
1499
1558
1500
1559
next_method:
1501
1560
}
@@ -1508,11 +1567,14 @@ function download($url, $destination)
1508
1567
);
1509
1568
if ($ webRequestInvocationStatusCode === 0 ) {
1510
1569
echo $ okMessage ;
1511
- return ;
1570
+ return true ;
1512
1571
}
1513
1572
// Otherwise we attempt other methods
1514
1573
}
1515
1574
1575
+ if ($ retry ) {
1576
+ return false ;
1577
+ }
1516
1578
1517
1579
echo "Error: Cannot download the installable archive. \n" ;
1518
1580
echo " One of the following prerequisites must be satisfied: \n" ;
0 commit comments