I have a php script in root of my site. I have added a cronjob in my cpanel. It is working with basic database operations like shown below:
<?php
require_once "classes/class.database.php";
$db = new database;
$db->connectToDB();
$data = date("Y/m/d H:i");
$res = $db->insertRow("cron",array("datetime"),array($data));
echo $res;
?>
In same file I have replaced these codes with codes below which are real codes that I want to schedule but it is not working. If I enter manually, it works but by this way it doesnt working.
Real Codes:
<?php
require_once "/home/domain/subdomain.domain.com/share/share.php";
$share = new share;
$share->sharePosts();
?>
I dont think there is an error in my code because it works manually however I want to be sure about that. Can I log output of this file? Thanks in advance.
I have finally solved the issue. I have enabled error logging with codes below.
error_reporting(E_ALL);
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
I have tried to mail myself (it is cpanels property) and just echo something. Mail came succesfully. Then I wrote wrong code (I wrote wrong path to "required_once"), when I execute manually, gives fatal error. Fatal errors not mailed. After that I replaced "require_once" with "include" to avoid fatal errors, then it noticed an error but this time it mailed to me. Error was "No such file." Then I tried path like that "/home/domain.com/yourcron.php" and no errors. In conclusion, all paths must be like "/home/domain.com/yourcron.php".