title: Laravel websocket pusher error and too many connection error
body: <p>I have Server with Centos OS, 10 core processors, 68 gb of ram</p>
  <p>I have created an app in which I am uploading csv of records 500k.</p>
  <p>After uploading, read the data in chunks and dispatched the job for each chunk</p>
  <pre><code>$file = ListcleaningFiles::find($this-&gt;file_id);
          
  if($file)
  {
      $data   =   file($file-&gt;file_location);
      
      // Chunking file
      $chunks = array_chunk($data, config('app.CLEANING_EMAIL_BATCH'));
      $header = [];
      $file-&gt;update(['total_chunks' =&gt; count($chunks)]);
  
      $counter = 0;
  
      $path = storage_path('app/public/counters/'.$file-&gt;id);
      if(!File::isDirectory($path)){
          File::makeDirectory($path, 0777, true, true);
      }
      
      foreach ($chunks as $key =&gt; $chunk) {
          $data = array_map('str_getcsv', $chunk);
  
          if ($key === 0) {
              $header = $data[0];
              unset($data[0]);
          }
          
          $queue_name = &quot;insert_emails_&quot;.$file-&gt;id.&quot;_&quot;.$key;
  
          $process_id = exec('nohup /usr/bin/php '.base_path().'/artisan queue:work --queue='.$queue_name.' --timeout=7200 --stop-when-empty &gt; /dev/null 2&gt;&amp;1 &amp; echo $!');
  
          File::put($path.'/'.$process_id.'_'.$key.'.txt','0');
          dispatch(new \App\Jobs\ImportEmails($data,$file-&gt;id,$key,$process_id))-&gt;onQueue($queue_name);
      }
  }else{
      Log::debug(&quot;File not found with id : &quot;.$this-&gt;file_id);
      return true;
  }
  </code></pre>
  <p>Import  job code</p>
  <pre><code>namespace App\Jobs;
  
  use Illuminate\Bus\Queueable;
  use Illuminate\Contracts\Queue\ShouldBeUnique;
  use Illuminate\Contracts\Queue\ShouldQueue;
  use Illuminate\Foundation\Bus\Dispatchable;
  use Illuminate\Queue\InteractsWithQueue;
  use Illuminate\Queue\SerializesModels;
  use App\Events\Listcleaning;
  use Illuminate\Support\Facades\Log;
  use App\Models\Mongo\ListcleaningFiles;
  use App\Models\Mongo\ListcleaningEmails;
  use Illuminate\Support\Str;
  use Illuminate\Bus\Batchable;
  use Illuminate\Support\Facades\Bus;
  use Cache;
  use DB;
  use File;
  use Storage;
  
  class ImportEmails implements ShouldQueue
  {
      use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
      public $rows;
      public $file_id;
      public $filelist;
      public $total_rows;
      public $domains;
      public $chunk_id;
      public $process_id;
      /**
       * Create a new job instance.
       *
       * @return void
       */
      public function __construct($rows,$file_id,$chunk_id,$process_id)
      {
          $this-&gt;rows = $rows;
          $this-&gt;file_id = $file_id;
          $this-&gt;filelist = ListcleaningFiles::find($file_id);
          if($this-&gt;filelist){
              $this-&gt;total_rows = $this-&gt;filelist-&gt;total_rows;
          }else{
              $this-&gt;total_rows = 0;
          }
          
          $this-&gt;chunk_id = $chunk_id;
          $this-&gt;process_id = $process_id;
      }
  
      /**
       * Execute the job.
       *
       * @return void
       */
      public function handle()
      {
          if (!$this-&gt;filelist) {
              exit(0);
          }
          
          if(is_array($this-&gt;rows) &amp;&amp; count($this-&gt;rows) &gt; 0)
          {
              $db = DB::connection('mongodb');
  
              $temp_emails = [];
              $temp_domains = [];
              $domain_data = [];
              $email_data = [];
  
              $counter = 1;
              $path = storage_path('app/public/counters/'.$this-&gt;filelist-&gt;id).'/'.$this-&gt;process_id.'_'.$this-&gt;chunk_id.'.txt';
              foreach($this-&gt;rows as $index =&gt; $row)
              {
                  File::put($path,$counter);
                  $counter++;
  
                  // remove columns that have no email
                  if(empty($row[1])){
                      continue;
                  }
  
                  // chek if the email is valid or not
                  if (!filter_var($row[1], FILTER_VALIDATE_EMAIL)) {
                      continue;
                  }
  
                  // remove emails that start with number
                  if ( is_numeric($row[1][0]) ) {
                      continue;
                  }
  
                  $email = $row[1];
  
                  //prevent duplicate emails
                  if(in_array(strtolower($email),$temp_emails))
                  {
                      continue;
                  }
                  $temp_emails[] = strtolower($email);
                  $domain = strtolower(substr(strrchr($email, &quot;@&quot;), 1));
  
                  $email_data[$email] = [
                      'file_id' =&gt; $this-&gt;filelist-&gt;id,
                      'fname' =&gt; $row[0],
                      'email' =&gt; $email,
                      'country' =&gt; $row[2],
                  ];
  
                  $this-&gt;logProgress($this-&gt;filelist);
              }
              
              
              
              $existing_emails = $db-&gt;collection('cleaned_emails_list')-&gt;where(['file_id' =&gt; $this-&gt;filelist-&gt;id])-&gt;whereIn('email',$temp_emails)-&gt;get();
              if(count($existing_emails) &gt; 0)
              {
                  foreach($existing_emails as $e)
                  {
                      if(isset($email_data[$e['email']]))
                      {
                          unset($email_data[$e['email']]);
                      }
                  }
              }
              $email_data = array_values($email_data);
              
              // insert emails to database
              if(count($email_data) &gt; 0){
                  $db-&gt;collection('cleaned_emails_list')-&gt;insert($email_data);
              }
              
          }
          //exec('kill -9 '.$this-&gt;process_id);
      }
  
      public function logProgress($file)
      {        
          $path = storage_path('app/public/counters/'.$this-&gt;filelist-&gt;id);
  
          $files = File::allFiles($path);
          $counter = 0;
          if(count($files) &gt; 0)
          {
              foreach($files as $f)
              {
                  $content = File::get($f);
                  $counter += (int)$content;
              }
          }
  
          $p = ($counter/$file-&gt;total_rows)*100;
  
          $file-&gt;update(['progress' =&gt; round($p,2)]);
          
          event(new Listcleaning([
              'type' =&gt; 'cleaning',
              'label' =&gt; 'Importing',
              'file_id' =&gt; $file-&gt;id,
              'progress' =&gt; round($p,2),
              'total_records' =&gt; $file-&gt;total_rows
          ]));
      }
  
      public function failed($exception)
      {
          $this-&gt;filelist-&gt;update(['is_cleaned' =&gt; 0,'is_locked' =&gt; 0,'is_mx_done' =&gt; 0,'is_ip_done' =&gt; 0,'is_ns_done' =&gt; 0]);
          Log::debug($exception);
      }
  }
  </code></pre>
  <p>websoket giving pusher connect error. increased the ulimit but still gives the same error or some time too many connections.</p>