Crontab does not run PHP function of the file in the directory

Asked

Viewed 352 times

1

I am running the following code on the Linux Server via Digital Ocean’s Putty

Inside the Crontab-e

This way

01 00 * * * /var/www/html/atualizador/atualizador-global.php

* * * * * /usr/bin/php7.3 http://www.sistemasjca.com.br/atualizador/cronteste.php

mailto="[email protected]"

However the PHP code does not run inside this cronteste.php file I am running a code to insert a line in the database, but I have no return, when I look at the database has not been inserted and also I do not receive email about the execution.

I also tried to run like this

* * * * * /usr/local/bin/php /var/www/html/atualizador/atualizador-global.php

The test code I’m trying to run is the following.

require_once("conexao-com-banco-users.php");
testaCron($conecta_login);

function testaCron($conecta){
    $query_bancos = "INSERT INTO banco_usuarios.tbl_usuarios(funcionario, usuario, email, senha, imagem) VALUES('CronjobUser','CronjobUser','CronjobUser','CronjobUser', '8D')";
    $resultado = mysqli_query($conecta, $query_bancos);

    if($resultado)
        echo 'usuario inserido com sucesso';
}

?>

This is the log I was pulled via "grep CRON /var/log/syslog" nux

  • Want PHP to access a remote page?

  • do not want to run a php code on the server side without involving the front end this code basically inserts a data into the database

  • But the execution of your command is like this, so I asked. It has nothing to do with front-end, actually line command or interact with the browser, unless you want, but there is "another 500", if you want the page to process is WGET, if the script is on the same server and failed is pq there is something wrong with the script, probably.

2 answers

1

|PROBLEM SOLVED|Logging in as a Root user on Putty via SSH

In the terminal I put

sudo apt-get install php7-cli

After that I entered with

sudo crontab -e

Inside crontab I called my php file this way.

* * * * * php /var/www/html/Atualizador/cronteste.php

After these steps recorded the data correctly in the database via Script at crontab.

inserir a descrição da imagem aqui

0

As far as I know the line command php does not access remote pages, or if you access it you probably need to release in php.ini the allow_url_fopen, still not necessarily run, actually run on the server, because it is an HTTP request and then would take the "HTTP response" and run on your machine, which would be a good chance to attack the machine with malicious code.

In short, none of this makes sense, if it is to access a sternal URL the correct is to use wget and so configure in crontab:

* * * * * wget 'http://www.sistemasjca.com.br/atualizador/cronteste.php'

Now if this isn’t working:

 * * * * * /usr/local/bin/php /var/www/html/atualizador/atualizador-global.php

It is because there may be some error in the script, maybe this is what you expect:

 * * * * * /usr/local/bin/php /var/www/html/atualizador/cronteste.php
            • /usr/local/bin/php /var/www/html/Updater/cronteste.php
  • @Andrewsgomes But does the PHP log emit something? Can you configure the PHP log in php.ini? As I said, it might be a mistake in your PHP script.

  • In PHP it’s success in the operation it includes the record in the database correctly when I call the file directly from php I place localhost/updater/cronteste.php and it returns me an echo saying it was successfully inserted. I saw this possibility on the internet too * * * * * /usr/bin/php /var/www/sistemasjca.com.br/updater/cronteste.php > /dev/null 2>&1 but I don’t know if I’m doing it wrong

  • @Andrewsgomes well ... we can’t speculate, use the tools you have in your favor, the Logs, go to php.ini, configure the logs to a file or email and run CRON again, then go to the log and see what it collected.

Browser other questions tagged

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