peppeocchi / php-cron-scheduler

PHP cron job scheduler
MIT License
808 stars 143 forks source link

codes don't work? #78

Open garsamba opened 5 years ago

garsamba commented 5 years ago

Im trying to use following code but it never worked for me. Is it possible to you help me to find my problem in this code ?

<?php
require_once __DIR__.'/vendor/autoload.php';

use GO\Scheduler;

$scheduler = new Scheduler();

$scheduler->php('test.php')->everyMinute();

$scheduler->run();

?>
peppeocchi commented 5 years ago

Hi @garsamba do you get any error back? For starter did you check the path to your autoloader? Did you also check the path to your test.php? Can you also check the php binary? Are you on linux? Did you setup correctly your crontab? What happens if you run your scheduler file directly php scheduler.php (assuming your scheduler file is called scheduler.php

I would start by debugging the above, you can add a file_exists function at the bottom, like

var_dump(file_exists(__DIR__.'/vendor/autoload.php'));
var_dump(file_exists('test.php'));

and then manually execute the scheduler, if you get false it means your paths are wrong. I would also run a which php in your command line to see the exact PHP bin path. And then if everything is ok and you're able to manually execute the scheduler, I would check that the crontab is set up correctly with crontab -l

Hope this helps

garsamba commented 5 years ago

var_dump(file_exists(__DIR__.'/vendor/autoload.php')); var_dump(file_exists(__DIR__.'/test.php'));

Results: bool(true) bool(true)

I'm renewing the page manually but I can't get any results.

rafaelmb commented 5 years ago

are you running your scheduler with cron?

garsamba commented 5 years ago

are you running your scheduler with cron?

i tried both, page refresh and https://cron-job.org/ crontab, but I didn't get the result

rafaelmb commented 5 years ago

did you try your local crontab file? Don't know if scheduler have some limitation on running via web.

garsamba commented 5 years ago

did you try your local crontab file? Don't know if scheduler have some limitation on running via web.

yes test.php file is processing when I refresh it manually

garsamba commented 5 years ago

did you try your local crontab file? Don't know if scheduler have some limitation on running via web.

Would you like to check with teamviewer?

rafaelmb commented 5 years ago

Your scheduler (calling test.php each minute) run using your cron file? Just following the project's front page instructions? Try this (not refreshing a page) to see if it works.

garsamba commented 5 years ago

Programlayıcınız (her dakika test.php'yi çağırarak) cron dosyanızı kullanıyor mu? Sadece projenin ön sayfa talimatlarını takip ediyor musun? Çalışıp çalışmadığını görmek için bunu deneyin (sayfayı yenilemeyin).

yes using -> https://prnt.sc/mpu3hs

rafaelmb commented 5 years ago

I see. That is not using the crontab file, this is using an external service. You could as well call test.php straight from cron-job.org I don't know if scheduler is designed to work with this. Maybe @peppeocchi quem shed some light on this.

garsamba commented 5 years ago

Your scheduler (calling test.php each minute) run using your cron file? Just following the project's front page instructions? Try this (not refreshing a page) to see if it works.

Why do we need to do a cron, page refresh?

garsamba commented 5 years ago

Hi @garsamba do you get any error back? For starter did you check the path to your autoloader? Did you also check the path to your test.php? Can you also check the php binary? Are you on linux? Did you setup correctly your crontab? What happens if you run your scheduler file directly php scheduler.php (assuming your scheduler file is called scheduler.php

I would start by debugging the above, you can add a file_exists function at the bottom, like

var_dump(file_exists(__DIR__.'/vendor/autoload.php'));
var_dump(file_exists('test.php'));

and then manually execute the scheduler, if you get false it means your paths are wrong. I would also run a which php in your command line to see the exact PHP bin path. And then if everything is ok and you're able to manually execute the scheduler, I would check that the crontab is set up correctly with crontab -l

Hope this helps

i tried these codes on another server which is installed php version 5.4.45. Codes are working great there. Do you think this script doesnt work on my server because my php version is 7.0.33 ?

peppeocchi commented 5 years ago

@garsamba I don't think that's the issue, the code is tested against php 7.0, 7.1 and 7.2

I believe you have different configurations on the two servers? Can you schedule to run a simple Closure? And then run php scheduler.php Did you check your system log files?

I would also compare the php .ini files between the two servers.

garsamba commented 5 years ago

@garsamba I don't think that's the issue, the code is tested against php 7.0, 7.1 and 7.2

I believe you have different configurations on the two servers? Can you schedule to run a simple Closure? And then run php scheduler.php Did you check your system log files?

I would also compare the php .ini files between the two servers.

i compared both php.ini and there is no huge difference. i fixed different functions and its still doesnt work. also i dont have any log in server log files about it. My cpanel licence key expired this month do you think it can be because of it ?

adamz01h commented 4 years ago

in your cron try * * * * * /usr/bin/php -f path/scheduler.php 1>> /dev/null 2>&1 then in scheduler.php at the top add chdir(__DIR__) post back results

alex-monte commented 3 years ago

I comment on my experience: Calling scheduler.php via web browser doesn't work, you have to run scheduler.php script via command line for it to work properly. For exemple: linux -> /usr/bin/php scheduler.php xampp -> D:/xampp/php/php.exe scheduler.php

Also if you use xampp you have to refine the consistent PHP_BINARY with your php binary at the beginning of your scheduler.php script. For example: define(PHP_BINARY, "D:/xampp/php/php.exe");