Cron Error Magento - Too late for the schedule - magento

hi im trying to set up a cronjob for magento..
have installed the AOE Scheduler and im getting the following errors while trying to run the .../cron.php:
Cron error while executing catalogrule_apply_all:
exception 'Mage_Core_Exception' with message 'Too late for the schedule.' in /home/www/web74/html/app/Mage.php:594
Stack trace:
#0 /home/www/web74/html/app/code/community/Aoe/Scheduler/Model/Observer.php(47): Mage::throwException('Too late for th...')
#1 /home/www/web74/html/app/code/core/Mage/Core/Model/App.php(1338): Aoe_Scheduler_Model_Observer->dispatch(Object(Varien_Event_Observer))
#2 /home/www/web74/html/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Aoe_Scheduler_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#3 /home/www/web74/html/app/Mage.php(447): Mage_Core_Model_App->dispatchEvent('default', Array)
#4 /home/www/web74/html/cron.php(46): Mage::dispatchEvent('default')
#5 {main}
thx

It is probably due to time zone difference and time mismatch. The time you are assigning in for a cron pocess has already crossed according to server.

Check configuration > system > cron. Make sure that your "schedule ahead" is far out enough in front of your actual system cron frequency. Tweak those numbers to resolve. etc.

If its not a timezone issue it is may caused by another corrupted cronjob. Check the cron_schedule table and look for jobs where the starting time (executed_at) is set but the finished_at column stays NULL. These jobs may throw an error which "crash" the cron chain and prevent other jobs to get executed.
To find the error, just create a little script to trigger the suspicious cron jobs directly. Place it in webroot and run it. For example
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app();
$a = new TheCron_Module_Model_Observer();
$a->triggerTheJob();
echo "\nDone\n";

Related

Magento cron job issue

I am having email sending issue in magento and I think it is due to cron jobs, following are the setting
cron job settings on cpanel
cron job settings on magento
I just cant figure out the issye
To Set Cron on Server:
You can set cron job on server for every 5 minutes:
php -f /home/fullpath/public_html/cron.php
Debug:
If cron Job still not work, Please add following code:
$isShellDisabled = true;
After below line of code:
$isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;

Order confirmation emails not working in Magento 1.9.3.2

My website is live and the order confirmation emails are neither being sent to the customer nor the admin. I am using Magento 1.9.3.2.
Please check whether Cron jobs are working or not, you can check easily by installing AOE SCHEDULER extension, make sure you have proper setting in System > Configuration > Advanced > System > Cron Also check whether you entered sender email in System > configuration> Sales> Sales email > Order emails.
Just to add to the above, out of the box the cronjobs are pre-configured in Magento, but you need to setup the actual job on your servers cron tab.
In SSH open the crontab;
crontab -e
Add this;
### MAGENTO CRON ###
*/1 * * * * cd /path/to/magento/ && sh cron.sh
Replaced /path/to/magento with the actual path your installation.
Magento allow 2 way to send email like below :
1) Using cron
2) Avoid cron
If you want without cron then use below change:
Open your order.php file at - app/code/core/Mage/Sales/Model/Order.php
And change :
//$mailer->setQueue($emailQueue)->send(); **// Comment this code.**
to:
$mailer-> send();
Note : Above change is not standard way in magneto so please implement file override way.
Go to : app/design/frontend/base/default/template/checkout/success.phtml:
Add following code on the top of the file code :
$order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order->loadByIncrementId($incrementId);
try
{
$order->sendNewOrderEmail();
}
catch (Exception $ex)
{
echo "Email Not Sent...";
}
$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();

warning using Parallel::ForkManager but only in Windows

I sometimes get this warning when using Parallel::ForkManager but only in Windows, not on a Unix based system. What does it mean and should I worry about it?
child process '-17108' disappeared. A call to waitpid outside of
Parallel::ForkManager might have reaped it.
Here is the sample code from the docs that my code is based on:
use LWP::Simple;
use Parallel::ForkManager;
my #links=(
["http://www.foo.bar/rulez.data","rulez_data.txt"],
["http://new.host/more_data.doc","more_data.doc"],
);
# Max 30 processes for parallel download
my $pm = Parallel::ForkManager->new(30);
LINKS:
foreach my $linkarray (#links) {
$pm->start and next LINKS; # do the fork
my ($link, $fn) = #$linkarray;
warn "Cannot get $fn from $link"
if getstore($link, $fn) != RC_OK;
$pm->finish; # do the exit in the child process
}
$pm->wait_all_children;
I had the similar issue and placing a sleep 1 before "$pm->start and next LINKS;"
fixed the issue. I guess its due to continues forking, where Perl lost track of the fork processes. I may be wrong!

CodeIgniter Cron Job on Shared Hosting?

I am trying to learn how to do my first cron job using CodeIgniter. In the past, it seemed the only way to do this with CI was to use the wget command instead of php.
The CodeIgniter User Guide, however, says that now you can do this from the command line, for example by running:
$ cd /path/to/project;
$ php index.php controller method
This works great using Terminal on my local setup. But when I use a similar command in the cron section of cPanel on my shared hosting, the task just returns the contents of index.php.
I'm not entirely sure what cPanel does with this command, so unsure as to whether it's using the command line at all.
Could someone explain how I might be able to set up a cron job on shared hosting using CodeIgniter please?
Here is the example code from the CodeIgniter user guide:
tools.php
public function message($to = 'World')
{
echo "Hello {$to}!".PHP_EOL;
}
}
?>
It's going to depend on your host. Cron jobs could really screw stuff up if you're not careful, so a lot of shared hosts don't allow it. You probably need to be on some virtual container (like a VPS, virtuozo, etc.) to do this. This isn't a CodeIgniter issue, but a hosting provider issue. Call them first.
We worked around this exact issue as follows:
Set up a normal php file that is scheduled by cron. Nothing to do with codeigniter yet
Inside it, you can make an fsocket or curl request to perform your regular CodeIgniter call as you do from the web.
Here's an example (say, cron.php)
#!/usr/local/bin/php.cli
<?php
DEFINE('CRON_CALL_URL','https://my_server/'); //
DEFINE('CRON_HTTPS_PORT', 443); // port to use during fsocket connetion
DEFINE('CRON_SSL_PREFIX', 'ssl://'); // prefix to be used on the url when using ssl
$current_time = now();
$md5_hash = md5('somevalue'.$current_time);
$url = CRON_CALL_URL.'MYCTRL/MYMETHOD';
$parts=parse_url($url);
//
$parts['query']='md5_hash='.$md5_hash.'&time='.$current_time;
$fp = fsockopen(CRON_SSL_PREFIX.$parts['host'],
isset($parts['port'])?$parts['port']:CRON_HTTPS_PORT,
$errno, $errstr, 30);
if (!$fp) {
} else {
if (!array_key_exists('query', $parts)) $parts['query'] = null;
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($parts['query'])."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($parts['query'])) $out.= $parts['query'];
fwrite($fp, $out);
fclose($fp);
}
}
?>
NOTE: Make sure that in your MYCTRL/MYMETHOD function you have
ignore_user_abort(true);
that way when you fsocket connection is closed, your script will still run to the end.
We actually have a bunch of these fsockets for various reasons. If you need to make sure that the call to that controller/method came from the cron script, you need to pass some additional hash values so that only cron and the script know it. Once the script is called it has access to any codeigniter functions. Works like a charm.
I've set up 100s of CI cronjob on shared hosting like this: create a short php script which calls the CI controller as if it was a webbrowser.
So, script.php contains this:
script #! /usr/local/bin/php -f /home/example/public_html/script.php
<?php
get_get_contents('http:example.com/cronjob/');
?>
Then set your cronjob in cPanel to call script.php
When it runs Script.php will call the Codeigniter Cronjob controller. There you have the entire CI framework at your disposal.
If you are going to call it like a web browser, why not replace the cronjob
command with:
wget http://example.com/cronjob/
instead of creating something new or simply
curl --suppress http://example.com/cronjob/`

How to set date.timezone for CodeIgniter to work with php 5.3

When date.timezone in php.ini is commented out, it gives me:
A PHP Error was encountered
Severity: Warning
Message: main(): It is not safe to
rely on the system's timezone
settings. You are required to use
the date.timezone setting or the
date_default_timezone_set() function.
In case you used any of those methods
and you are still getting this
warning, you most likely misspelled
the timezone identifier. We selected
'America/Los_Angeles' for '-8.0/no
DST' instead
Filename: controllers/helloworld.php
Line Number: 2
When I have
date.timezone = "America/Los_Angeles"
It gives me this:
Server error The website encountered
an error while retrieving
http://localhost/ci/index.php/helloworld.
It may be down for maintenance or
configured incorrectly. Here are some
suggestions: Reload this web page
later. HTTP Error 500 (Internal Server
Error): An unexpected condition was
encountered while the server was
attempting to fulfill the request.
I am using php 5.3, CodeIgniter 2.0.0, and Apache 2.2.
Update 1:
I tried loading a test.php without CodeIgniter, where the first 3 lines of test.php is
date_default_timezone_set('America/Los_Angeles');
echo date("l j \of F Y h:i:s A");
And it works fine, different timezones also works fine too.
So I suspect the problem is from CodeIgniter.
If you Googled "CodeIgniter PHP 5.3" you would have found this article pretty quickly :)
http://philsturgeon.co.uk/blog/2009/12/CodeIgniter-on-PHP-5.3
To fix this, you only need to edit the main index.php for your CodeIgniter application:
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
This modification is something you will probably need to make for any CodeIgniter application running on PHP 5.3 and can easily be modified to your local timezone. There is a full list of supported timezones in the PHP manual here.
Yes, if you cannot directly edit the php.ini file, placing...
ini_set('date.timezone', 'America/New_York');
...as the first line in CI's index.php works fine.
Reference: PHP's Available Timezones
write in your index.php codeigniter...
/*
|---------------------------------------------------------------
| TimeZone
|---------------------------------------------------------------
|
| default Time Zone
|
*/
if ( function_exists( 'date_default_timezone_set' ) )
date_default_timezone_set('Asia/Jakarta');
Running well in my codeigniter
this is the simple way to do it
$timezone = "Asia/Calcutta";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
//echo date('d-m-Y H:i:s');
$localtime=date('H:i:s');
$sql="INSERT INTO hits (ip,edate,curtime,page_name) VALUES ('$ip', CURDATE(),'$localtime','$filename') ";
date.timezone is intended to go in your php.ini or .htaccess file.
you could do an ini_set('date.timezone', 'America/Los_Angeles'); in the first line of your script and get the desired results.
edit your config.php file
from
$config['time_reference'] = 'local';
to
$config['time_reference'] = 'UTC';

Resources