CodeIgniter Forums
Cron on GoDaddy - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Cron on GoDaddy (/thread-32648.html)



Cron on GoDaddy - El Forum - 07-29-2010

[eluser]spider pig[/eluser]
I have been working on a web site using CI that is hosted on GoDaddy.

One of the problems I had was that I need a script to run using cron to send batches of emails from a queue. I have done this many times but on cPanel web hosting. I would have a cron entry like this:

Code:
wget -O /dev/null http://www.mydomain.com/admin/cron_send_emails

However on GoDaddy, this comes up with a 404 error. I tried a few variations but could not get it to work.

I also tried CI on the command line but could not get it to work.

After some experimentation, I came up with this hack. Rather than trying to access a CI page, I created a php script called cron.php with the following code:

Code:
<?php
    $handle = fopen("http://www.mydomain.com/admin/cron_send_emails", "r");
    fclose($handle);
?>

You will need to make sure the .htaccess file is changed so the script can be run:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|cron\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

I then use cron to run the cron.php script which in turn runs the CI page.

Hope that helps someone.


Cron on GoDaddy - El Forum - 07-30-2010

[eluser]xzela[/eluser]
Do you actually have access to the crontab with your GoDaddy Account?

If so, you can make that cron.php file as a bash script.
Simply add #!/bin/bash to the top of the cron.php file like so:
Code:
#!/bin/bash
<?php
....

Then add a job to your crontab which executes the file:
Code:
/path/to/php5 -q /path/to/cron.php
// the path to php5 should be: /usr/bin/php5,



Cron on GoDaddy - El Forum - 09-11-2010

[eluser]gene777[/eluser]
Hi,

The Issue:
Thanks for making this post. I am trying to accomplish the same task however I am getting an error when I do. The following error was emailed to me by the Cron Daemon.

Code:
/web/cgi-bin/php5: /usr/local/lib/libpng12.so.0: no version information available (required by /web/cgi-bin/php5)
Content-type: text/html

However I do think I did this correctly. Just to be clear I also did the following:


In the website directory
Step 1. I created an .htaccess file with the info you provided. It looks like this:
Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|cron\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Step 2. I also created a cron.php file with the same info you provided, except referencing my own url where the code igniter index.php is located. I placed this in the same folder as the CodeIgniter site index.php.

The site directory looks like this:
.htaccess
cron.php
index.php

The cron.php script looks like this:
Code:
#!/bin/bash
<?php
    $handle = fopen("http://mywebsitelocation/index.php", "r");
    fclose($handle);
?>

Step 3A. I CHMOD 705 the cron.php and the index.php in the site directory.
Step 3B. I also CHMOD 705 the contents of the application and system folder using Transmit. I'm thinking that should make code igniter executable by the crontab.
Step 4. I set up the cron tab in GoDaddy referencing the cron.php file. (This is on GoDaddy GRID hosting - I don't know if that makes a difference or not.)
Step 5. I set up several cron jobs - to run the script once every ten minutes so I could:
1.) Check the reliability of GoDaddy's crontab. Does it run every hour as I scheduled or will it break more often then not?
2.) Get faster feedback whether or not the cron idea will work.

So any thoughts as to why this might not work would be greatly appreciated. Best,

Gene

------
Update: 2010/09
After running the cron for a little bit I have noticed that I am still getting this error, however a simple procedural code in the loaded view which uses the regular mail() function does seem to work. However a second email which should also be loaded via the controller using the CodeIgniter mail library does not seem to work, hence the error. The code for the controller's email is:

Controller Mail Action:
Code:
$server_time = strftime('%c');
        $this->load->library('email');

        $this->email->from('mysenderemailaddress', 'My Name');
        $this->email->to('mydestinationemailaddress');

        $this->email->subject('object-oriented mail test @ server time:'.$server_time);
        $this->email->message('object-oriented mail test @ server time: '.$server_time. ' It was executed from the controller, welcome, in the controllers folder.');    
        $this->email->send();

If you have any thoughts about how to debug this I would greatly appreciate it. Thanks in advance.


Cron on GoDaddy - El Forum - 09-12-2010

[eluser]spider pig[/eluser]
Hi gene777

[quote author="gene777" date="1284252891"]Hi,
Code:
/web/cgi-bin/php5: /usr/local/lib/libpng12.so.0: no version information available (required by /web/cgi-bin/php5)
Content-type: text/html
[/quote]

libpng12 is a library (plugin) that handles PNG image files. If you are not modifying PNG files, I'd say there was a problem with the server.

Your Step 1 look correct, however, the web address you are trying to open in Step 2 doesn't look right. It looks like you are accessing the main index.php file for the entire web site rather than the particular controller that sends the emails:

Code:
#!/bin/bash
<?php
    $handle = fopen("http://mywebsitelocation/index.php/send_emails", "r");
    fclose($handle);
?>

I didn't bother setting permissions. Normally your FTP software (I use Coda) does this for you.

The one thing I did omit from my original post was the line of code used in cron. So here it is:

Code:
/web/cgi-bin/php5 "$HOME/html/cron.php"

It is based on the default code GoDaddy has when you create a new cron job.

GoDaddy's cron only allows you to run a script up to twice an hour. Just made use the check box "Run twice an hour" is ticked. I just adjusted how many emails are sent in each batch to compensate.

Hope that helps.


Cron on GoDaddy - El Forum - 09-12-2010

[eluser]gene777[/eluser]
Thanks Dale. The PNG Library info makes sense. I completely missed that part. I think there must be something wrong with the server because I am definitely not doing anything related to image files.

I am indeed using the main website's index.php as the url. It seems to work fine as far as executing the particular task I have in mind. I simply set the controller I wanted to run as the default controller in config/routes.php

I am still getting an error message, but at least I do know that CodeIgniter will work when running it via the cron, which is a big relief. Thanks again.

Gene