2

I am working on a PHP project in OVH server. I want to start a script once a day to push an alert.

The script works when i call it manually myself. But when i wait the CRON, i always got the error : exitcode 255 in my logs.

cron.php

include('/home/name/path/bdd.php');

error_reporting( E_ALL );
ini_set('display_errors', '1');

$var = "INSERT INTO `alerts`(`alert_text`, `alert_user`, `alert_link`, `alert_date`) VALUES (:text, :id, :link, NOW())";
$stmt = $pdo->prepare($var);

    //Lancement
$insert = $stmt->execute(array(
    ':text' => 'hello',
    ':id' => '2', 
    ':link' => '#'
));

OVH logs

[2023-12-31 13:42:02] ## OVH ## START - 2023-12-31 13:42:02.401426 executing: /usr/local/php7.3/bin/php /home.XXX/name/path/cron.php 
[2023-12-31 13:42:02] 
[2023-12-31 13:42:02] ## OVH ## END - 2023-12-31 13:42:02.455282 exitcode: 255

I tried to change include paths for absolute, to modify my functions or to work procedurally. Nothing change.

5
  • If your code works when manually calling it, then it can't be the code you've posted in the question since you have a syntax error in your INSERT query - you're missing the opening back tick before alert_date. What is bdd.php? You're including it both before you call sendAlert() and again inside. We need more details about your code. Commented Dec 31, 2023 at 14:22
  • Yes, just a copy paste error, sorry ! Commented Dec 31, 2023 at 14:25
  • It's crucial that you post your exact code if you want us to be able to help. We can't detect possible typos, logic issues etc if we don't get to see the actual code. Just copy/paste it into the question "as-is" (with reasonable formatting, ofc). Commented Dec 31, 2023 at 14:26
  • I modified the post, but i can't do more for the copy/paste. Commented Dec 31, 2023 at 15:02
  • Anything showing in the PHP error logs? If not, the next step is probably adding your own logging. I’d keep it simple, and try to have it log as early as possible in the script. You might need to have a log entry before and after each existing line of code Commented Jan 1, 2024 at 14:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.