Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2.  
  3. function requestUrl($url)
  4. {
  5. $ch = curl_init();
  6. curl_setopt($ch, CURLOPT_URL, $url);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. $output = curl_exec($ch);
  9. curl_close($ch);
  10. echo md5($output)."\n";
  11. }
  12.  
  13. $urls = [
  14. "http://php.net", // Will work fine
  15. "https://stackoverflow.com/", // Will fail
  16. ];
  17.  
  18. // First, request an HTTPS url, required for the bug to occur
  19. requestUrl("https://facebook.com");
  20.  
  21. foreach ($urls as $url) {
  22. $pid = pcntl_fork();
  23. if ($pid == -1) {
  24. throw new \Exception('Could not fork');
  25. } else if ($pid) {
  26. // Parent process
  27. pcntl_waitpid($pid, $status);
  28.  
  29. print_r([
  30. "URL" => $url,
  31. "Successful Exit" => pcntl_wifexited($status) ? "Yes" : "No",
  32. "Exit Code" => pcntl_wexitstatus($status)
  33. ]);
  34.  
  35. echo "\n";
  36. } else {
  37. // Child process
  38. requestUrl($url);
  39. exit(0);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement