FATAL ERROR - PHP Curl

Asked

Viewed 79 times

0

Notice: Undefined offset: 0 in C: Users aprendiz151ciee Desktop PHP - Webserver root DASHBOARD file.php on line 62

Fatal error: Maximum Execution time of 30 Seconds exceeded in C: Users aprendiz151ciee Desktop PHP - Webserver root DASHBOARD file.php on line 145

Does anyone know why you made a mistake?!
At home it works perfectly, arrives at the company... This mistake happens. It must be because at home I use XAMPP with PHP 7.1 and here at work I use the USB WEBSERVER?

<?php


$x = new Nulogy();
$retorno = $x->iniciar();
echo $retorno;

class Nulogy{

public $u;
public $s;
public $url;
public $post;
public $resposta;
public $cookie;
public $token;
public $urlDownload;
public $dir;
public $nome;
public $ds;
public $arquivo;
public function __construct(){

  $this->u = 'login';
  $this->s = 'senha';
  $this->dir = dirname(__FILE__).DIRECTORY_SEPARATOR.'download'.DIRECTORY_SEPARATOR;
  $this->cookie = dirname(__FILE__).DIRECTORY_SEPARATOR. '/cookie/' .'NULOGY[COOKIE]' . rand(0, 999999) . '.txt'; 
}
public function iniciar(){
  $this->url = 'https://packmanager.nulogy.net/sign_in';
  $this->loginPlayLoad();
  $this->post();
  $validarLogin = $this->validarLogin();
  if($validarLogin === 'logado'){
  return $this->linkDownload();
  }else{
    return $validarLogin;
  }
}
public function loginPlayLoad(){
  $this->getTokenLogin();
  if($this->token){
    $data['utf8'] = '✓';
    $data['authenticity_token'] = $this->token;
    $data['return'] = '';
    $data['uv_login'] = '';
    $data['user[login]'] = $this->u;
    $data['user[password']= $this->s;
    $data['commit'] = 'Sign in';
    $data['authenticity_token'] = $this->token;
    $data['authenticity_token'] =$this->token;
  }else{
    return false;
  }
  $this->post = http_build_query($data);
  return true;
}
public function getTokenLogin(){
  $this->url = 'https://packmanager.nulogy.net/sign_in';
  $this->get();
  preg_match_all('/meta content="(.*?)" name="csrf-token"/', $this->resposta, $matches, PREG_SET_ORDER, 0);
  $token = $matches[0][1];
  if($token){
    return $this->token = $token;
  }else{
    return array('status' => false,'resposta' => 'Não foi possível encontrar CSRF-TOKEN' );
  }
  return false;
}
public function validarLogin(){
  if(preg_match_all('/title>(.*?)<.title>/', $this->resposta, $matches, PREG_SET_ORDER, 0)){
    $titlo = $matches[0][1];
  }else{
  $titlo = false;
  }  

  if((isset($titlo) && ($titlo === 'Sign in to PackManager') )) {
    return $titlo . ' Login ou senha inválidos.'; 
  }else{
    return 'logado';
  }
}
public function linkDownload(){
  $url = [
  'https://packmanager.nulogy.net/canned_reports/job_productivity?utf8=%E2%9C%93&generate_flag=true&filter_choice=project_customer&query%5B0%5D%5Bactual_job_start_at%5D%5Boperator%5D=between&query%5B0%5D%5Bactual_job_start_at%5D%5Bfrom_threshold%5D=2017-Jul-2+9%3A00+PM&query%5B0%5D%5Bactual_job_start_at%5D%5Bto_threshold%5D=2017-Jul-3+11%3A46+PM&columns%5B0%5D=project_code&columns%5B1%5D=item_code&columns%5B2%5D=actual_job_start_at&columns%5B3%5D=actual_job_end_at&columns%5B4%5D=line_name&columns%5B5%5D=performance&columns%5B6%5D=availability&columns%5B7%5D=line_efficiency&columns%5B8%5D=units_produced&columns%5B9%5D=units_expected&columns%5B10%5D=unit_of_measure&columns%5B11%5D=standard_units_per_hour&columns%5B12%5D=duration&order_by=actual_job_start_at&order_direction=desc&authenticity_token='.urlencode($this->token).'&authenticity_token='.urlencode($this->token).'&format=csv',
  'https://packmanager.nulogy.net/jobs.csv?authenticity_token='.urlencode($this->token).'&customer_name=&from_scheduled_start_at=2017-Jul-2+00%3A00&has_production=all&item_code=&line_leader=all&line_leader_id=all&line_name=&page=1&project_code=&reconciliation_status=all&signed_off=no&status=all&to_scheduled_end_at=2017-Jul-3+23%3A59&utf8=%E2%9C%93',
  'https://packmanager.nulogy.net/canned_reports/job_downtime?utf8=%E2%9C%93&generate_flag=true&filter_choice=item_class_name&query%5B0%5D%5Bactual_job_start_at%5D%5Boperator%5D=between&query%5B0%5D%5Bactual_job_start_at%5D%5Bfrom_threshold%5D=2017-Jul-2+9%3A00+PM&query%5B0%5D%5Bactual_job_start_at%5D%5Bto_threshold%5D=2017-Jul-3+11%3A55+PM&columns%5B0%5D=job_id&columns%5B1%5D=line_name&columns%5B2%5D=downtime_reason_code&columns%5B3%5D=downtime_reason_name&columns%5B4%5D=downtime_duration&columns%5B5%5D=downtime_notes&order_by=actual_job_start_at&order_direction=desc&authenticity_token='.urlencode($this->token).'&authenticity_token='.urlencode($this->token).'&format=csv'];
  $nome = [0 => 'produtividade do trabalho.csv',1 => 'Trabalhos.csv' , 2 => 'inatividade do trabalho.csv'];
  $i = 0;

  foreach($url as $u):
    $this->urlDownload = $u;
    $this->nome = $nome[$i++];
    echo $this->dw();
  endforeach;
}
public function header(){
  $header = [
      "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
      "Accept-Language: en-US,en;q=0.5",
      "Accept-Encoding: gzip, deflate, br",
      "Connection: keep-alive",
      "Upgrade-Insecure-Requests: 1",
      "Content-Type: application/x-www-form-urlencoded"
  ];
  return $header;
}
public function dw(){
    $this->url = $this->urlDownload;
    $this->get();
    $dw = $this->resposta;
    $this->arquivo = $this->dir.$this->nome;
    if($this->arquivosExiste()){
      
    file_put_contents($this->arquivo , $dw);
    $ret =  'Arquivo salvo na pasta: ' . $this->dir . '<br>';    
    }else{
      $ret = 'Algum problema foi encontrado :/';
    }
    return $ret;
}
public function arquivosExiste(){
  if (is_file($this->arquivo)){
      unlink($this->arquivo);
   }
  return true;
}
public function post(){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $this->url);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $this->post);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36');
  curl_setopt($ch, CURLOPT_REFERER, "https://packmanager.nulogy.net/sign_in");
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION,2);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header());
  curl_setopt($ch, CURLOPT_ENCODING, '');
  $this->resposta = curl_exec($ch);
}
public function get(){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $this->url);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36');
  curl_setopt($ch, CURLOPT_REFERER, "https://packmanager.nulogy.net/sign_in");
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header());
  curl_setopt($ch, CURLOPT_ENCODING, '');
  $this->resposta = curl_exec($ch);
}
}

  • The message is telling you that you have exceeded the execution time limit. Probably in your company there must be some firewall or proxy rule that doesn’t let you browse such a site. Already checked if you can access everything you need without php?

  • Hell, as a matter of fact, I’ve banned a lot of websites here. This image appears here: https://prnt.sc/fyhpwv But the site that I access in this code, is released by the system. It’s the site we use to see the production.

  • So in case I should contact them to free my access?! But what should I ask to release? If the site I access to download CSV files is released...

  • So there’s your problem. If it is something for the work itself, contact the staff who manage the network of your desktop and explain that you need to access such site. It can be http, https, ftp, etc. You have to see what you need and what service you need and align it with your desktop network.

  • Right. Thank you very much Fernando!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.