title: Execution of php file with commande
body: <p>I use symfony 2.8 for my project. this is the code of php file that i would to execute with commande:</p>
  
  <pre><code> use Video\IntelligenceBundle\Entity\Entry;
   use Video\IntelligenceBundle\Entity\Visits;
   use Doctrine\ORM\EntityManager;
   use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
   use Symfony\Component\Console\Input\InputInterface;
   use Symfony\Component\Console\Input\InputOption;
   use Symfony\Component\Console\Output\OutputInterface;
   use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  
  
   class ConvertVisitsIncomeCommand extends ContainerAwareCommand
   {
  public function configure()
  {
      $this-&gt;setName('app:convert-visits')
          -&gt;setDescription('Convertir les entrée de la table visits a la 
  table entry')
      ;
  }
  
  protected function execute(InputInterface $input, OutputInterface 
  $output)
  {
  
      /** @var EntityManager $em */
  
      $em = $this-&gt;getContainer()-&gt;get('doctrine')-&gt;getManager();
  
     // $em = $this-&gt;getDoctrine()-&gt;getManager();
  
     $output-&gt;writeln("sss"); 
      /** @var Video\IntelligenceBundle\Entity\Visits $visit */
      $visitsRepository = $em-&gt;getRepository(Visits::class);
  
      $visits = $visitsRepository-&gt;findAll();
      $groupedVisitsByPerson = [];
  
      /** @var Video\IntelligenceBundle\Entity\Visits $visit */
      foreach ($visits as $visit)
          $groupedVisitsByPerson[$visit-&gt;getIdPerson()][] = $visit;
  
      $visitDate = null;
      $leaveDate = null;
      $tmp = [];
      foreach ($groupedVisitsByPerson as $personId =&gt; $visits) {
          try {
  
              $i      = 0;
              $length = count($visits);
              $visitDate = null;
              $leaveDate = null;
              /** @var \AppBundle\Entity\Visits $visit */
              foreach ($visits as $visit) {
                  $i++;
                  if($visit-&gt;getVisitDate()-&gt;getTimestamp() &lt;= 0) {
                      $em-&gt;remove($visit);
                      continue;
                  }
                  if(is_null($visitDate)) {
                      $visitDate = $visit-&gt;getVisitDate();
                      $tmp[] = $visit;
                      if($length == $i) {
                          $entry = new Entry();
                          $entry
                              -&gt;setVisitDate($visitDate)
                              -&gt;setLeaveDate(null)
                              -&gt;setIdPerson($personId)
                              -&gt;setCamera($visit-&gt;getCamera());
                          $em-&gt;persist($entry);
                          $output-&gt;writeln("&lt;success&gt;".$entry-&gt;getIdPerson()." added&lt;/success&gt;");
                      }
                  } else {
                      $diff = $visit-&gt;getVisitDate()-&gt;diff($visitDate);
                      $seconds = $diff-&gt;s + $diff-&gt;i * 60 + $diff-&gt;h * 3600;
                      if($length == $i) {
                          $tmp[]     = $visit;
                          $leaveDate = $visit-&gt;getVisitDate();
                          if($leaveDate == $visitDate) {
                              $leaveDate = null;
                          }
  
                          $entry = new Entry();
                          $entry
                              -&gt;setVisitDate($visitDate)
                              -&gt;setLeaveDate($leaveDate)
                              -&gt;setIdPerson($personId)
                              -&gt;setCamera($visit-&gt;getCamera());
                          $em-&gt;persist($entry);
                          $output-&gt;writeln("&lt;success&gt;".$entry-&gt;getIdPerson()." added&lt;/success&gt;");
  
                          $visitDate = null;
                          $leaveDate = null;
                      }
                      elseif($seconds &gt; 0 &amp;&amp; $seconds &lt;= 60 ) {
                          $leaveDate = $visit-&gt;getVisitDate();
                          $tmp[]     = $visit;
                      }
                      elseif($seconds &gt; 60) {
                          $entry = new Entry();
                          $entry
                              -&gt;setVisitDate($visitDate)
                              -&gt;setLeaveDate($leaveDate)
                              -&gt;setIdPerson($personId)
                              -&gt;setCamera($visit-&gt;getCamera());
                          $em-&gt;persist($entry);
  
                          $visitDate = $visit-&gt;getVisitDate();
                          $leaveDate = null;
                          $tmp[]     = $visit;
                      }
                  }
              }
  
              foreach ($tmp as $visit)
                  $em-&gt;remove($visit);
  
              $em-&gt;flush();
          } catch (\Exception $e) {
              $output-&gt;writeln("&lt;error&gt;".$e-&gt;getMessage()." &lt;/error&gt;");
  
  
          }
  
      }
  
   }
     }
  </code></pre>
  
  <p>when i try to execute this code with this commande :</p>
  
  <p><code>sudo php /opt/lampp/htdocs/vi-old/app/console app:convert-visits --env=prod</code></p>
  
  <p>I have this issue </p>
  
  <blockquote>
    <p>[Doctrine\DBAL\Exception\ConnectionException]<br>
    An exception occured in driver: SQLSTATE[HY000] [2002] No such file or
    directory</p>
  </blockquote>
  
  <p>who can help me to solve this problem please.                                          </p>