Closed JarbyDev closed 9 years ago
Hi @thomas1216,
I am sorry for this migration issue and I will try to help you. Do you use Laravel 4 or Laravel 5? The artisan command php artisan migrate --path=vendor/liebig/cron/src/migrations
is for a Laravel 5 installation but the CronServiceProvider
Provider is only for use with Laravel 4.
For Laravel 4 please add 'Liebig\Cron\CronServiceProvider'
to your 'providers'
array in the /path/to/laravel/app/config/app.php
file and use the artisan command php artisan migrate --package="liebig/cron"
.
For Laravel 5 please add 'Liebig\Cron\Laravel5ServiceProvider'
to your 'providers'
array in the /path/to/laravel/config/app.php
file and use the artisan command php artisan migrate --path=vendor/liebig/cron/src/migrations
.
I hope this helps.
Hi, @liebig,
I use laravel 5,
now i get this error message
[PDOException] SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin g password: YES)
Now Laravel finds the migration files and is trying to start the migration process. But the database connection is closed from the server because the authentication information are wrong. Please check your config/database.php
file, correct the login data and try again.
@liebig
But i dont recognized that homestead, that is not mysql database user. mysql database is at godaddy server. including laravel code. i dont have databases intalled on my local machine.
this is the seetings i got saved on config/database.php
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'RBC'), 'username' => env('DB_USERNAME', 'dev'), 'password' => env('DB_PASSWORD', 'bigproject'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ],
Hi @thomas1216,
I am sorry, I can't help you with your database connection and godaddy. Please ask godaddys support team for the correct MySQL username and password. If you have another questions to the Cron library don't hesitate to open a new issue.
Thank you, Marc
@liebig but i got the connection settings, because i got other software and always the connection is successful.
Cron is using the default database connection, that you configure in the config/database.php
file. Also homestead
is not part of the Cron source code, so it seems that you set this value somewhere. I cannot help you with a Access denied
error while connecting to your database because Cron uses only the default Laravel database abstraction layer.
@thomas1216, I am sorry, you were right! I installed a fresh Laravel 5 installation and added a MySQL database and got the same connection error. In Laravel 5 you can use .env
files to configure your database connection, mail connection and other for each environment (prod, test, dev, ...). So please edit your /path/to/laravel/.env
file or if you don't need this feature, just rename or delete this file:
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
I hope that helps.
Thanks after make that changed connect perfectly.
One more question, i have a hostname database in mysql each hostname got a cron definition in the database,
i have the following 7 Cron Expressions Schedule definition are in the mysqldb 0 22 * * 3#2 0 22 * * 3#3 0 22 * * 3#4 0 22 * * 3,6,9,12 3#2 0 22 * * 3,6,9,12 3#3 0 22 * * 3,6,9,12 3#4 40 21 * * *
How make all those 7 Crons Run in the Same Php file Schedule.php and each cronexpression will fire a different file, Ex Cron 0 22 * * 3#4 will fire include php file called File.php, but only enable one Cron Expression at a time, like if the next Schedule is 0 22 * * 3#3 only enabled that Cron, i like ike rendered one file at time, no overlapping.
Thanks for all you help
Okay, I hope I get it right:
You can include your Schedule.php
at your /path/to/laravel5/app/Providers/AppServiceProvider.php
file at the boot method:
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
//...
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() {
// Include or require
include 'Schedule.php';
}
}
Your Schedule.php
should look like:
\Event::listen('cron.collectJobs', function() {
\Cron::add('cron1', '0 22 * * 3#2', function() {
// Include or require
include 'cron1.php';
});
\Cron::add('cron2', '0 22 * * 3#3', function() {
// Include or require
include 'cron2.php';
});
//...
});
I don't understand: but only enable one Cron Expression at a time, like if the next Schedule is 0 22 * * 3#3 only enabled that Cron
. Your expressions are different, so that 0 22 * * 3#2
will run on the second Tuesday of the month but 0 22 * * 3#3
will run on the third Tuesday of the month. So only one job will run at a specific Tuesday. No need to disable the other jobs...
Hello @liebig
I appreciate all your help.
i tried your suggestion but i get the following message after insert the code at my Schedule.php
Fatal error: Class 'Event' not found in /home/thomas/public_html/hosts/schedule.php on line 46
my laravel path is /home/thomas/public_html/hosts/laravel5/
For me this works great!
/path/to/laravel5/app/Providers/AppServiceProvider.php
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
//...
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() {
// Include or require
include 'Schedule.php';
}
}
/path/to/laravel5/app/Providers/Schedule.php
<?php
\Event::listen('cron.collectJobs', function() {
\Cron::add('cron1', '0 22 * * 3#2', function() {
// Include or require
include 'cron1.php';
});
\Cron::add('cron2', '0 22 * * 3#3', function() {
// Include or require
include 'cron2.php';
});
//...
});
php artisan cron:list
+---------+--------------+-----------+
| Jobname | Expression | Activated |
+---------+--------------+-----------+
| cron1 | 0 22 * * 3#2 | Enabled |
| cron2 | 0 22 * * 3#3 | Enabled |
+---------+--------------+-----------+
So please check your PHP code. I can only support Cron, not your source code. But if you have another question about Cron, please open a new issue.
Thank you, Marc
hello @liebig
I get the following error message when i tried to open the Schedule file at web browser Fatal error: Class 'Event' not found in /home/thomas/public_html/hosts/app/Providers/schedule.php on line 46
and the code in line 46 is:
<?php \Event::listen('cron.collectJobs', function() { \Cron::add('cron1', '0 22 * * 3#2', function() { // Include or require include 'cron1.php'; }); \Cron::add('cron2', '0 22 * * 3#3', function() { // Include or require include 'cron2.php'; }); //... }); ?>
Thanks for you Help :+1:
Of course you got a Class not found error
while opening the Schedule file directly. Why are you doing this? There is no include for Laravel or Cron in this file! This Schedule file will be included from Laravel, after Laravel was started, Cron was loaded and the Cron job was executed. So all these classes are there. But when you access this file directly all these classes are not loaded. This is not a problem with Cron. Please note that I cannot teach you basic PHP things. I am here to give you free support for the free Cron library.
Thanks, Marc
i follow your install instructions, but i'm stuck on database migrate i enter the following command php artisan migrate --path=vendor/liebig/cron/src/migrations
but i get the following message
[Symfony\Component\Debug\Exception\FatalErrorException] Class 'Liebig\Cron\CronServiceProvider' not found