Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php artisan cron:run Not working #93

Closed
tanmaysakhale24 opened this issue Sep 8, 2017 · 13 comments
Closed

Php artisan cron:run Not working #93

tanmaysakhale24 opened this issue Sep 8, 2017 · 13 comments

Comments

@tanmaysakhale24
Copy link

After running php artisan cron:run
It shows
PHP Warning: Module 'pgsql' already loaded in Unknown on line 0
[ReflectionException]
Method Liebig\Cron\RunCommand::handle() does not exist

After running any command list,run and keygen. i got the same error.
Please help me with this issue

@liebig
Copy link
Owner

liebig commented Sep 8, 2017

Which version of Laravel are you using? Did you installed Cron as described in the manual?

@tanmaysakhale24
Copy link
Author

Laravel Framework 5.5.2
Installed as same in the documentation. Cron::add function is working fine for me and records are getting updated in cron_job and cron_manager.
One more issue i have
I want to make the cron function (Basic insert query for testing like inserting 10000 records in table) timeout after 30 sec of execution time. But script continue to run for 48 sec successfully. I want to store the timeout error in cron_job.
I made changes in etc/php/7.0/cli/php.ini file by changing max_execution_time= 3 and changing max_input_time=3. But then also cron continue to complete its script, is there any way i can put a timeout limit to cron::add or any other options u have

@liebig
Copy link
Owner

liebig commented Sep 11, 2017

@tanmaysakhale24
Copy link
Author

This helped me thanks. It is generating a fatal error and that error is not getting stored in cron_job table.

Help me with this issue too
After running php artisan cron:run
It shows
PHP Warning: Module 'pgsql' already loaded in Unknown on line 0
[ReflectionException]
Method Liebig\Cron\RunCommand::handle() does not exist

After running any command list,run and keygen. i got the same error.

Completed Following steps.
Installing Fresh Laravel

laravel new cronproject
php artisan key:generate
creating database
changing env file with the DB details
php artisan migrate
Add "liebig/cron": "dev-master" to your /path/to/laravel/composer.json file at the "require": section (Find more about composer at http://getcomposer.org/)
Run the composer update liebig/cron --no-dev command in your shell from your /path/to/laravel/ directory
Add 'Liebig\Cron\Laravel5ServiceProvider' to your 'providers' array in the /path/to/laravel/config/app.php file
Migrate the database with running the command php artisan migrate --path=vendor/liebig/cron/src/migrations
Publish the configuration file with running the command php artisan vendor:publish - now you find the Cron configuration file at /path/to/laravel/config/liebigCron.php and this file won't be overwritten at any update

I am calling the cron from controller
http://127.0.0.1:8000/cron

    Cron::add('CreateUser', '* * * * *', function() {
        $cnt=5000;
        $saved="";
        for($i=0;$i<=$cnt;$i++) {
            $user = new User;

            $user->name = "tanmay" . rand();
            $user->email = 'tanmay.sakhale' . rand() . '@gmail.com';
            $user->password = 'password';
            $saved = $user->save();
        }
        if(!$saved){
            return "Error:421";
        } else {
            return "Success";
        }
    });        
    $report = Cron::run();
    print_r ($report);
}

If i try it from AppServiceProvider by writing it on boot() function. How to call this cron automatically not having idea how to do this ??

Please help

@liebig
Copy link
Owner

liebig commented Sep 11, 2017

The Method Liebig\Cron\RunCommand::handle() does not exist error seems to be a namespace problem, because Liebig\Cron\Run does exist but Liebig\Cron\RunCommand does not. So please check your code! Please have a look at the README how to use Cron's integrated route also.

@tanmaysakhale24
Copy link
Author

image
This is showing when i am typing the command

@tanmaysakhale24
Copy link
Author

image
Now my cron started running by the run command. I checked it in the cron_job table.

Just i am not able to see list command. I am doing print_r to see the list of cron jobs.
How to solve this ReflectionException
Thanks for your help

@liebig
Copy link
Owner

liebig commented Sep 11, 2017

Can you please test to rename (in vendor directory) cron/src/Liebig/Cron/ListCommand.php line 37

public function fire() {

to

public function handle() {

and try the cron:list command again?
Thank you.

@tanmaysakhale24
Copy link
Author

It started working. Thank you for the help.

@liebig
Copy link
Owner

liebig commented Sep 11, 2017

Okay, then we have to change all the fire method names to handle for the command files. A PR would be awesome.

@liebig liebig mentioned this issue Sep 12, 2017
@liebig
Copy link
Owner

liebig commented Sep 12, 2017

I added a Pull Request for this issue.
@tanmaysakhale24 Please have a look at it and test it. You can download the laravel-5.5 branch and extract it to your vendor directory (or only the three command files KeygenCommand.php, ListCommand.php and RunCommand.php) and execute the commands. Thank you.

@liebig
Copy link
Owner

liebig commented Sep 13, 2017

I have tested the changes and they seem to work. PR is merged and closed.

@liebig liebig closed this as completed Sep 13, 2017
@tanmaysakhale24
Copy link
Author

Ok I will try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants