1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Domain;
- use Illuminate\Console\Command;
- class ApachePingWebsitesWithCurl extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'apache:ping-websites-with-curl';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Test if response is 200 for all websites';
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $findCustomer = \App\Models\Customer::first();
- $findHostingPlan = \App\Models\HostingPlan::first();
- for ($i = 0; $i <= 50000; $i++) {
- $newSubscription = new \App\Models\HostingSubscription();
- $newSubscription->customer_id = $findCustomer->id;
- $newSubscription->hosting_plan_id = $findHostingPlan->id;
- $newSubscription->domain = 'next-server-1-'.$i.rand(1111,9999).'.test.multiweber.com';
- $newSubscription->save();
- }
- return;
- // Retrieve all website configurations from the database
- $websiteConfigs = Domain::get();
- foreach ($websiteConfigs as $config) {
- $domain = $config->domain;
- $cmd = "curl -s -o /dev/null -w '%{http_code}' http://$domain";
- $response = shell_exec($cmd);
- if ($response == 200) {
- $this->info("Website $domain is up and running");
- } else {
- $this->warn("Website $domain is down");
- }
- }
- return 0;
- }
- }
|