Cron Job - Doesn’t Work

Asked

Viewed 360 times

-1

<?php
include $_SERVER['DOCUMENT_ROOT'].'/aaa/core/database/connect.php';
include $_SERVER['DOCUMENT_ROOT'].'/aaa/functions/general.php';
include $_SERVER['DOCUMENT_ROOT'].'/aaa/functions/users.php';

$sql = $conn->query("SELECT `user_id` FROM `users`") or die(mysqli_error($conn));
    while ($row = $sql->fetch_assoc()) {
        $user_id = $row['user_id'];
        $inc_per_min = income_per_minute($user_id);

        if ($inc_per_min > 0) {
            $conn->query("UPDATE `game_data` SET `money_hand` = `money_hand` + '$inc_per_min' WHERE `user_id` = '$user_id'") or die(mysqli_error($conn));
        }
    }
?>

That’s the code I want to run every minute. This is what I have in charge of the cron:

Current Cron Jobs
Minuto  Hora    Dia Mês Dia útil    Comando Ações
*   *   *   *   *   /home/MyUserName/public_html/aaa/cron_stack.php

Can someone tell me why it doesn’t work?

  • It does not work because it is not calling the PHP executable to interpret the script.

2 answers

1

You need to put in cron the command as you would run it on the command line.

If the executable is a PHP script, so you would run it like this:

php /home/MyUserName/public_html/aaa/cron_stack.php

Hence, in the cron, would look like this:

*   *   *   *   *   php /home/MyUserName/public_html/aaa/cron_stack.php
  • But the script seems not to run with this cron command..

-1

  • This command served the purposes of the other question - is to download a remote file.

  • Making a web request to run a local PHP is not exactly what I would call a technical solution. There rare cases where it is necessary, this does not seem to me to be one of them.

Browser other questions tagged

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