fork download
  1. <?php
  2. $filepath = "https://www.google.com";
  3.  
  4. print_r($filepath);
  5. $maxRetries = 3; // Control number of retries here
  6. $timeout = 10; // Timeout in seconds
  7. $contextX = stream_context_create([
  8. 'http' => [
  9. 'timeout' => $timeout,
  10. ]
  11. ]);
  12.  
  13. $attempt = 0;
  14. $homepage = false;
  15. echo 'hi';
  16. // while ($attempt < $maxRetries) {
  17. // try {
  18. // $homepage = file_get_contents($filepath, false, $contextX);
  19. // if ($homepage !== false) {
  20. // break; // Success, exit loop
  21. // }
  22. // print_r('Failed to fetch content');
  23. // } catch (Exception $e) {
  24. // $attempt++;
  25. // if ($attempt >= $maxRetries) {
  26. // print_r("Failed to fetch content after $maxRetries attempts: " . $e->getMessage());
  27. // }
  28. // // Exponential backoff: sleep for 2^attempt seconds
  29. // // sleep(pow(2, $attempt));
  30. // }
  31. // }
  32. $ch = curl_init();
  33. curl_setopt ($ch, CURLOPT_URL, $filepath);
  34. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  35. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
  36. $homepage = curl_exec($ch);
  37. print_r($homepage);
  38. ?>
  39.  
Success #stdin #stdout 0.03s 26128KB
stdin
Standard input is empty
stdout
https://www.google.comhi