Crontab stops working when Oracle connection arrives in PHP

Asked

Viewed 44 times

0

I am trying to run a routine by crontab, but it hangs on the connection to the Database. But if I run the file normally as:

php /var/www/html/pasta/teste.php

He returns the data to me normally:

Resultado

This is my crontab:

*/1 * * * * /usr/bin/php /var/www/html/pasta/teste.php >> /var/log/teste.log

This is my php file:

<?php
echo 'Iniciou..  ';

try{
    echo 'Vai conectar?..   ';

    $connection = oci_connect('user' , 'password', 'HOST/DB');

    echo 'Conectou..    ';
} catch (PDOException $e)
{
    $mensagem .= "   Erro: " . $e->getMessage();
    echo $mensagem;
}

$sql = "SELECT * FROM tabela where rownum <= 2";
$querySQL = oci_parse($connection, $sql);
oci_execute($querySQL);
oci_fetch_all($querySQL, $stmt);

foreach($stmt as $row)
{ 
    var_dump($row) ;
    exit;
}
?>

The crontab result looks like this (/var/log/test.log):

Iniciou..  Vai conectar?..

Version of the OS:

VERSION="18.04.2 LTS (Bionic Beaver)"
PRETTY_NAME="Ubuntu 18.04.2 LTS"                                                                                        
VERSION_ID="18.04"

1 answer

1


Puts variables in crontab:

ORACLE_HOME=/usr/lib/oracle/12.1/client64
LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
*/1 * * * * /usr/bin/php /var/www/html/pasta/teste.php >> /var/log/teste_laudo.log

Browser other questions tagged

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