3v4l.org

run code in 300+ PHP versions simultaneously
<?php class GoogleTranslate { /** * Retrieves the translation of a text * * @param string $source * Original language of the text on notation xx. For example: es, en, it, fr... * @param string $target * Language to which you want to translate the text in format xx. For example: es, en, it, fr... * @param string $text * Text that you want to translate * * @return string a simple string with the translation of the text in the target language */ public static function translate($source, $target, $text) { // Request translation $response = self::requestTranslation($source, $target, $text); // Get translation text // $response = self::getStringBetween("onmouseout=\"this.style.backgroundColor='#fff'\">", "</span></div>", strval($response)); // Clean translation $translation = self::getSentencesFromJSON($response); return $translation; } /** * Internal function to make the request to the translator service * * @internal * * @param string $source * Original language taken from the 'translate' function * @param string $target * Target language taken from the ' translate' function * @param string $text * Text to translate taken from the 'translate' function * * @return object[] The response of the translation service in JSON format */ protected static function requestTranslation($source, $target, $text) { // Google translate URL $url = "https://translate.google.com/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=es-ES&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e"; $fields = array( 'sl' => urlencode($source), 'tl' => urlencode($target), 'q' => urlencode($text) ); if(strlen($fields['q'])>=5000) throw new \Exception("Maximum number of characters exceeded: 5000"); // URL-ify the data for the POST $fields_string = ""; foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); // Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_USERAGENT, 'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1'); // Execute post $result = curl_exec($ch); // Close connection curl_close($ch); return $result; } /** * Dump of the JSON's response in an array * * @param string $json * The JSON object returned by the request function * * @return string A single string with the translation */ protected static function getSentencesFromJSON($json) { $sentencesArray = json_decode($json, true); $sentences = ""; foreach ($sentencesArray["sentences"] as $s) { $sentences .= isset($s["trans"]) ? $s["trans"] : ''; } return $sentences; } } echo (new GoogleTranslate())->translate("en","vi","hello");

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.10.0130.00516.98
8.5.00.0140.00920.43
8.4.160.0070.00423.86
8.4.150.0090.00416.96
8.4.140.0140.00717.93
8.4.130.0100.01017.83
8.4.120.0140.00722.45
8.4.110.0100.01019.00
8.4.100.0090.01218.02
8.4.90.0120.00920.65
8.4.80.0050.00518.81
8.4.70.0080.00918.81
8.4.60.0120.00819.12
8.4.50.0100.01120.66
8.4.40.0100.01017.98
8.4.30.0060.01319.64
8.4.20.0140.00719.54
8.4.10.0030.01719.81
8.3.280.0070.00616.30
8.3.270.0130.00616.82
8.3.260.0120.00716.91
8.3.250.0120.00717.14
8.3.240.0100.00416.64
8.3.230.0100.00916.67
8.3.220.0070.00919.04
8.3.210.0090.00218.43
8.3.200.0060.00616.87
8.3.190.0030.00617.32
8.3.180.0110.00918.92
8.3.170.0070.01316.86
8.3.160.0040.01417.12
8.3.150.0110.00717.33
8.3.140.0070.01020.69
8.3.130.0080.00018.35
8.3.120.0130.00620.66
8.3.110.0030.00516.98
8.3.100.0030.00720.41
8.3.90.0050.00316.78
8.3.80.0090.00318.43
8.3.70.0110.00718.36
8.3.60.0110.00418.55
8.3.50.0050.00917.68
8.3.40.0180.00418.79
8.3.30.0110.00718.93
8.3.20.0080.00021.73
8.3.10.0040.00423.48
8.3.00.0080.00023.53
8.2.290.0120.00718.99
8.2.280.0110.00418.45
8.2.270.0100.01018.90
8.2.260.0110.00416.88
8.2.250.0140.00318.71
8.2.240.0110.00719.06
8.2.230.0030.00620.94
8.2.220.0060.00324.06
8.2.210.0040.00426.77
8.2.200.0100.00018.41
8.2.190.0030.01716.58
8.2.180.0150.00018.35
8.2.170.0070.00722.96
8.2.160.0070.00720.35
8.2.150.0020.00524.18
8.2.140.0050.00324.66
8.2.130.0080.00021.06
8.2.120.0050.00326.35
8.2.110.0080.00021.04
8.2.100.0060.00617.91
8.2.90.0060.00318.34
8.2.80.0040.00418.21
8.2.70.0000.00818.04
8.2.60.0000.00817.75
8.2.50.0030.00518.10
8.2.40.0070.00020.42
8.2.30.0070.00020.57
8.2.20.0040.00418.17
8.2.10.0080.00018.18
8.2.00.0050.00218.22
8.1.330.0100.00816.55
8.1.320.0100.00916.53
8.1.310.0110.00716.97
8.1.300.0060.01119.80
8.1.290.0000.01218.88
8.1.280.0060.00925.92
8.1.270.0040.00422.09
8.1.260.0040.00426.35
8.1.250.0030.00628.09
8.1.240.0060.00322.58
8.1.230.0120.00020.89
8.1.220.0000.00817.74
8.1.210.0060.00318.77
8.1.200.0030.00617.35
8.1.190.0040.00417.38
8.1.180.0080.00018.10
8.1.170.0000.00818.49
8.1.160.0080.00018.98
8.1.150.0030.00520.23
8.1.140.0000.00817.79
8.1.130.0000.00719.06
8.1.120.0000.00817.45
8.1.110.0040.00417.46
8.1.100.0040.00417.51
8.1.90.0050.00217.46
8.1.80.0070.00017.46
8.1.70.0000.00717.39
8.1.60.0000.00817.64
8.1.50.0030.00717.61
8.1.40.0000.00717.56
8.1.30.0040.00417.60
8.1.20.0020.00617.58
8.1.10.0080.00017.54
8.1.00.0040.00417.43
8.0.300.0000.00720.15
8.0.290.0070.00016.88
8.0.280.0000.00718.40
8.0.270.0050.00217.30
8.0.260.0030.00316.93
8.0.250.0030.00317.05
8.0.240.0080.00017.08
8.0.230.0000.00717.04
8.0.220.0030.00316.90
8.0.210.0000.00716.90
8.0.200.0030.00316.95
8.0.190.0050.00316.95
8.0.180.0000.00716.85
8.0.170.0030.00617.00
8.0.160.0040.00417.03
8.0.150.0030.00516.87
8.0.140.0020.00616.95
8.0.130.0010.00515.14
8.0.120.0020.00516.94
8.0.110.0010.00616.93
8.0.100.0020.00616.96
8.0.90.0050.00316.92
8.0.80.0030.01116.93
8.0.70.0030.00516.92
8.0.60.0040.00416.86
8.0.50.0050.00316.90
8.0.30.0090.00817.07
8.0.20.0090.00717.21
8.0.10.0000.00817.07
8.0.00.0080.00816.84
7.4.330.0030.00315.55
7.4.320.0030.00316.45
7.4.300.0040.00416.68
7.4.290.0000.00716.63
7.4.280.0000.00716.50
7.4.270.0000.00716.56
7.4.260.0050.00216.61
7.4.250.0050.00216.55
7.4.240.0020.00516.45
7.4.230.0000.00716.48
7.4.220.0010.00716.60
7.4.210.0100.00516.51
7.4.200.0020.00516.52
7.4.190.0020.00516.55
7.4.180.0000.00716.51
7.4.160.0060.01016.61
7.4.150.0000.00716.43
7.4.140.0070.00917.54
7.4.130.0060.00616.39
7.4.120.0110.00516.54
7.4.110.0080.00516.59
7.4.100.0100.00616.64
7.4.90.0090.00416.38
7.4.80.0090.00417.91
7.4.70.0070.00516.37
7.4.60.0070.00516.36
7.4.50.0070.00316.42
7.4.40.0050.00716.36
7.4.30.0000.00716.24
7.4.20.0000.00716.40
7.4.10.0070.00016.43
7.4.00.0030.00515.72
7.3.330.0110.00214.93
7.3.320.0090.00714.81
7.3.310.0080.00616.56
7.3.300.0120.00216.36
7.3.290.0110.00316.42
7.3.280.0080.01016.37
7.3.270.0170.00416.21
7.3.260.0110.00616.44
7.3.250.0110.00916.53
7.3.240.0130.00616.46
7.3.230.0110.00916.45
7.3.220.0170.00316.46
7.3.210.0100.00916.40
7.3.200.0090.00816.44
7.3.190.0090.00916.40
7.3.180.0110.00716.43
7.3.170.0100.00816.44
7.3.160.0150.00516.31
7.3.150.0130.00816.38
7.3.140.0170.00316.19
7.3.130.0120.00716.38
7.3.120.0120.00616.28
7.3.110.0120.00816.24
7.3.100.0120.00616.16
7.3.90.0170.00316.61
7.3.80.0150.00416.19
7.3.70.0140.00516.40
7.3.60.0120.00616.44
7.3.50.0130.00516.45
7.3.40.0150.00416.45
7.3.30.0150.00416.56
7.3.20.0100.01016.36
7.3.10.0140.00516.43
7.3.00.0210.00416.45
7.2.340.0130.00516.48
7.2.330.0130.00616.65
7.2.320.0090.00916.65
7.2.310.0130.00516.45
7.2.300.0130.00616.37
7.2.290.0150.00416.57
7.2.280.0170.00216.19
7.2.270.0170.00216.45
7.2.260.0120.00616.30
7.2.250.0180.00016.40
7.2.240.0140.00516.36
7.2.230.0190.00016.42
7.2.220.0150.00416.28
7.2.210.0150.00316.44
7.2.200.0150.00616.49
7.2.190.0120.00816.37
7.2.180.0190.00016.55
7.2.170.0160.00316.65
7.2.160.0110.00816.44
7.2.150.0130.00816.61
7.2.140.0160.00316.45
7.2.130.0130.00616.77
7.2.120.0170.00216.59
7.2.110.0200.00016.71
7.2.100.0120.00816.56
7.2.90.0180.00416.68
7.2.80.0100.01016.64
7.2.70.0170.00316.52
7.2.60.0110.00516.84
7.2.50.0150.00416.66
7.2.40.0120.00816.63
7.2.30.0190.00617.31
7.2.20.0180.00817.17
7.2.10.0150.00817.13
7.2.00.0110.01017.93
7.1.330.0190.00015.63
7.1.320.0150.00315.57
7.1.310.0120.00615.46
7.1.300.0180.00015.58
7.1.290.0130.00515.45
7.1.280.0180.00015.59
7.1.270.0110.00915.55
7.1.260.0190.00015.62
7.1.250.0110.00715.31
7.1.240.0130.00515.44
7.1.230.0130.00415.42
7.1.220.0150.00315.35
7.1.210.0150.00415.39
7.1.200.0080.00715.59
7.1.190.0110.00715.37
7.1.180.0130.00515.42
7.1.170.0110.00815.44
7.1.160.0040.01315.47
7.1.150.0180.00816.18
7.1.140.0460.00816.08
7.1.130.0250.00616.01
7.1.120.0140.00915.86
7.1.110.0100.01015.52
7.1.100.0200.00315.79
7.1.90.0180.00815.93
7.1.80.0140.00815.80
7.1.70.0150.00715.42
7.1.60.0270.01124.41
7.1.50.0230.01024.21
7.1.40.0200.00824.04
7.1.30.0280.00824.21
7.1.20.0350.00924.08
7.1.10.0120.00715.20
7.1.00.0150.00315.28
7.0.330.0150.00315.21
7.0.320.0170.00014.93
7.0.310.0110.00615.20
7.0.300.0120.00515.28
7.0.290.0110.00715.04
7.0.280.0230.00015.22
7.0.270.0130.00315.27
7.0.260.0210.00415.07
7.0.250.0150.00215.38
7.0.240.0130.00315.14
7.0.230.0150.00315.38
7.0.220.0130.00515.29
7.0.210.0150.00215.16
7.0.200.0140.00315.10
7.0.190.0130.00515.29
7.0.180.0100.00715.06
7.0.170.0150.00215.22
7.0.160.0150.00415.21
7.0.150.0170.00215.22
7.0.140.0130.00415.02
7.0.130.0090.00815.19
7.0.120.0140.00415.28
7.0.110.0090.00915.13
7.0.100.0160.00315.03
7.0.90.0120.00515.07
7.0.80.0060.01115.27
7.0.70.0170.00715.19
7.0.60.0130.00415.17
7.0.50.0100.00715.13
7.0.40.0290.00415.30
7.0.30.0170.00015.07
7.0.20.0100.00715.22
7.0.10.0120.00615.23
7.0.00.0130.00415.23
5.6.400.0110.00715.91
5.6.390.0110.00715.80
5.6.380.0130.00415.97
5.6.370.0110.00615.67
5.6.360.0110.00615.84
5.6.350.0170.00015.93
5.6.340.0110.00615.61
5.6.330.0080.00915.83
5.6.320.0110.00615.87
5.6.310.0160.00415.65
5.6.300.0100.00715.79
5.6.290.0160.00015.94
5.6.280.0130.00415.67
5.6.270.0140.00215.88
5.6.260.0120.00415.68
5.6.250.0170.00015.80
5.6.240.0130.00315.92
5.6.230.0170.00016.05
5.6.220.0120.00516.02
5.6.210.0130.00415.94
5.6.200.0100.00715.86
5.6.190.0120.00415.98
5.6.180.0170.00015.88
5.6.170.0170.00016.10
5.6.160.0160.00015.95
5.6.150.0090.00916.08
5.6.140.0080.00815.91
5.6.130.0170.00015.94
5.6.120.0110.00715.92
5.6.110.0170.00015.98
5.6.100.0080.00815.96
5.6.90.0170.00015.88
5.6.80.0140.00315.78
5.6.70.0150.00516.09
5.6.60.0160.00015.95
5.6.50.0090.00615.79
5.6.40.0140.00315.82
5.6.30.0120.00415.93
5.6.20.0120.00415.90
5.6.10.0110.00615.81
5.6.00.0150.00315.82

preferences:
41.18 ms | 403 KiB | 5 Q