You are here:  » Host Not Allowing Cron Jobs


Host Not Allowing Cron Jobs

Submitted by Rocket32 on Sun, 2013-10-20 07:09 in

Host company does not allow cron jobs, but recommends using outside free sources to run cron jobs. Can I use an outside cron service to run a Price Tapestry cron job for slow import, import all, or import modified? I looked at free cron services which ask for the URL to Call. What would I enter in the url to call for a slow import cron or any other crons if possible?

Submitted by support on Sun, 2013-10-20 11:03

Hi Rocket32.

No problem - you can use an external cron service to call cron.php, but before doing so, I would apply a mod that will enable you to use a different password for CRON than for your main /admin/ area.

To do this, edit config.advanced.php and look for the following code at line 2:

  $config_adminPassword = "normalpassword";

...REPLACE with:

   if (strpos($_SERVER["REQUEST_URI"],"cron.php")!==FALSE)
   {
     // password for cron.php
     $config_adminPassword = "cronpassword";
   }
   else
   {
     // normal password for /admin/
     $config_adminPassword = "normalpassword";
   }

Then, the URL you need to submit is simply:

http://www.example.com/scripts/cron.php?password=cronpassword

Check your site a reasonable time after the job was first scheduled to run, and check that all Automation Tool jobs (if using) are showing a last run time consistent with the schedule, and then further that all feeds are showing an Imported time also consistent with the schedule. If everything shows as up to date then no need to worry about using slow import, but if it appears the process was timed out at any stage during fetch / import let me know and I'll help you with slow import via external cron service options.

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Sun, 2013-10-20 22:19

I tried the above. It fail to connect when using the cronpassord different from admin. Message was

HTTP/1.1 401 Authorization Required
Date: Sun, 20 Oct 2013 16:50:04 GMT
Content-Type: text/html
Content-Length: 25
Connection: keep-alive
Server: Apache/2
X-Powered-By: PHP/5.3.13

401 Unauthorized

Last URL: http://www.exampleurl.com/scripts/cron.php?password=cronpassword
Last HTTP status: 401

When I made the cron password the same as the admin password, it connected and timed out almost immediately.

Yes it does time out on the fetch & the import.

Also I tried doing a slow import from my browser & after a certain amount of imports, it locks out the mysql user with the following

User 'user_name' has exceeded the 'max_questions' resource (current value: 75000)].

It may not do any good doing it unless several mysql users were available during import. I still would like to know the method for the slow_import fron external cron if possible.

Submitted by support on Mon, 2013-10-21 08:39

Hi Rocket32,

A couple of things to try here, firstly however, my apologies I had made a typo in the multiple password mod; the test to check if the request was for cron.php contained a scrupulous "/" - the correct REPLACEment code should be:

   if (strpos($_SERVER["REQUEST_URI"],"cron.php")!==FALSE)
   {
     // password for cron.php
     $config_adminPassword = "cronpassword";
   }
   else
   {
     // normal password for /admin/
     $config_adminPassword = "normalpassword";
   }

(corrected above also)

Now, when you say that it disconnects almost immediately, it's possible that the remote CRON service is simply triggering the request and not waiting for any response. To check if this is the case if you edit scripts/cron.php and look for the following code at line 2:

  set_time_limit(0);

...and REPLACE with:

  ignore_user_abort(true);
  set_time_limit(0);

Now regarding the max MySQL "questions", the 1-second sleep every 100 products imported significantly reduces server load, which is described in this thread.

If no joy with the above, or anyway if you would like to try the slow import via CRON (this will require that the external cron service follows HTTP (302) redirects) let me know which Price Tapestry distribution you are running and I will forward those files for you.

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Tue, 2013-10-22 03:00

Above code works fine. But still no love on with timeouts. I am using the latest PT version(13/03A). I think I need the HTTP(302) redirect version.

Submitted by support on Tue, 2013-10-22 08:13

Hi Rocket32,

No problem - I'll prepare a scriptable version of the slow import tool for 13/03A today and forward to you by email.

Cheers,
David.
--
PriceTapestry.com

Submitted by Rocket32 on Wed, 2013-10-23 23:58

Hey David. Did you forward that copy? I might have missed the email. If I did, could you send it again.

Thanks,
Rocket32

Submitted by support on Thu, 2013-10-24 10:48

Just sent!

Cheers,
David.
--
PriceTapestry.com