ApachePingWebsitesWithCurl.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Domain;
  4. use Illuminate\Console\Command;
  5. class ApachePingWebsitesWithCurl extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'apache:ping-websites-with-curl';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Test if response is 200 for all websites';
  19. /**
  20. * Execute the console command.
  21. *
  22. * @return int
  23. */
  24. public function handle()
  25. {
  26. $findCustomer = \App\Models\Customer::first();
  27. $findHostingPlan = \App\Models\HostingPlan::where('id',2)->first();
  28. for ($i = 0; $i <= 1000; $i++) {
  29. $newSubscription = new \App\Models\HostingSubscription();
  30. $newSubscription->customer_id = $findCustomer->id;
  31. $newSubscription->hosting_plan_id = $findHostingPlan->id;
  32. $newSubscription->domain = 'next-server-1-'.$i.rand(1111,9999).'.test.multiweber.com';
  33. $newSubscription->save();
  34. }
  35. return;
  36. // Retrieve all website configurations from the database
  37. $websiteConfigs = Domain::get();
  38. foreach ($websiteConfigs as $config) {
  39. $domain = $config->domain;
  40. $cmd = "curl -s -o /dev/null -w '%{http_code}' http://$domain";
  41. $response = shell_exec($cmd);
  42. if ($response == 200) {
  43. $this->info("Website $domain is up and running");
  44. } else {
  45. $this->warn("Website $domain is down");
  46. }
  47. }
  48. return 0;
  49. }
  50. }