3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generateAffiliateCommands(int $companyId, int $daysBack) { $sections = [ 'AFFILIATES' => [ "affiliate:cac-sync-affiliates %d", "affiliate:cac-sync-commission-plan-reports %d" ], 'COMMISSIONS' => [ "affiliate:cac-sync-commissions %d --dateFrom=\\\"%s\\\" --dateTo=\\\"%s\\\"" ], 'REGISTRATIONS' => [ "affiliate:cac-sync-registrations %d --dateFrom=\\\"%s\\\" --dateTo=\\\"%s\\\"" ], 'TRANSACTIONS' => [ "affiliate:cac-sync-transactions %d --dateFrom=\\\"%s\\\" --dateTo=\\\"%s\\\"" ] ]; $commands = []; // AFFILIATES section $commands[] = "## AFFILIATES ##"; $affiliateCmds = []; foreach ($sections['AFFILIATES'] as $index => $cmd) { $formatted = sprintf($cmd, $companyId); if ($index > 0) { $formatted = "php artisan $formatted"; } $affiliateCmds[] = $formatted; } $commands[] = implode(' && ', $affiliateCmds); // Generate 30-day periods starting from -1 backwards $periods = []; $chunkSize = 30; $currentTo = -1; while (abs($currentTo) < $daysBack) { $currentFrom = $currentTo - $chunkSize + 1; // Ensure we don’t go beyond -daysBack if (abs($currentFrom) > $daysBack) { $currentFrom = -$daysBack; } $periods[] = [$currentFrom, $currentTo]; // Next chunk ends where this one starts $currentTo = $currentFrom - 1; } // Flip to oldest first (-daysBack → -1) $periods = array_reverse($periods); // Generate other sections foreach (['COMMISSIONS', 'REGISTRATIONS', 'TRANSACTIONS'] as $section) { $commands[] = "## $section ##"; $sectionCmds = []; foreach ($periods as $i => [$from, $to]) { if ($to !== -1) { $to = $to + 1; } $cmd = sprintf($sections[$section][0], $companyId, "$from days", "$to days"); if ($i > 0) { $cmd = "php artisan $cmd"; } $sectionCmds[] = $cmd; } $commands[] = implode(' && ', $sectionCmds); } return implode("\n\n", $commands); } function dateToDaysAgo(string $date) { // Create DateTime objects $given = new DateTime($date); $now = new DateTime(); // current date and time // Calculate difference $diff = $now->diff($given); // Total days difference $daysAgo = $diff->days; // If the given date is in the past, return negative if ($given < $now) { return $daysAgo + 1; } else { return -$daysAgo - 1; } } $companyId = 223; $date = '2023-11-13 15:44:50'; echo generateAffiliateCommands($companyId, dateToDaysAgo($date));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.20.0220.01417.55
8.5.10.0380.00516.98
8.5.00.0210.01116.81
8.4.170.0320.00620.55
8.4.160.0310.00820.59
8.4.150.0300.01319.92
8.4.140.0350.00917.91
8.4.130.0320.01117.83
8.4.120.0370.01017.86
8.4.110.0410.00817.76
8.4.100.0420.00717.85
8.4.90.0400.00617.98
8.4.80.0310.01418.15
8.4.70.0410.00818.07
8.4.60.0400.00817.72
8.4.50.0370.01017.96
8.4.40.0400.01017.68
8.4.30.0420.00617.81
8.4.20.0370.01217.62
8.4.10.0350.01317.82
8.3.300.0280.01118.82
8.3.290.0340.00718.68
8.3.280.0340.00718.68
8.3.270.0320.01216.77
8.3.260.0370.01116.90
8.3.250.0320.01116.96
8.3.240.0430.00616.81
8.3.230.0370.00816.89
8.3.220.0380.01116.79
8.3.210.0360.01316.89
8.3.200.0330.01016.77
8.3.190.0410.00516.93
8.3.180.0460.00816.77
8.3.170.0390.00816.84
8.3.160.0360.01016.89
8.3.150.0390.00916.54
8.3.140.0420.00516.95
8.3.130.0340.00716.66
8.3.120.0310.00916.91
8.3.110.0340.00916.80
8.3.100.0400.00716.90
8.3.90.0410.01016.55
8.3.80.0430.00616.94
8.3.70.0370.01116.92
8.3.60.0400.01116.64
8.3.50.0250.00816.66
8.3.40.0330.01118.23
8.3.30.0260.01017.95
8.3.20.0280.00818.03
8.3.10.0290.00918.16
8.3.00.0180.00617.95

preferences:
30.39 ms | 403 KiB | 5 Q