### Cron Jobs - OsTICKET - Windows Virtual Server

Hi, I don't know how to set up my cron job, my osticket is running fine, I can access and create tickets from the web portal, the problem is when I want to create tickets via email, can someone help me ????

This is my cron job

#!/usr/bin/php -q
<?php
/*********************************************************************
rcron.php

PHP script used for remote cron calls.

Peter Rotich <peter@osticket.com>
Copyright (c)  2006-2013 osTicket
http://www.osticket.com

Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.

vim: expandtab sw=4 ts=4 sts=4:

**********************************************************************/

Configuration: Enter the url and key. That is it.

url => URL to api/task/cron e.g http://yourdomain.com/support/api/tasks/cron

key => API's Key (see admin panel on how to generate a key)

#

$config = array(
'url'=>'"My IP server"/xampp/htdocs/osticket/api/tasks/rcron',
'key'=>'My key generated from the OSTICKET portal'
);

#pre-checks
function_exists('curl_version') or die('CURL support required');

#set timeout
set_time_limit(30);

#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);

if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status) && $status[1] == 200)
exit(0);

echo $result;
exit(1);
?>

  • RBGE replied to this.

    jsbanjo If you're running on a Windows server, you'll want to use Task Scheduler. Basically get PHP to run every 2 minutes (or whatever you need) and pass it the api/cron.php file as an argument. You'll want to make sure this task runs under the user account IIS does (IIS_USR???) just for security reasons.

      Also that file is not a cron job... thats the cron.php.

      You use PHP to call the file something like:
      PATH\TO\PHP\php.exe -f PATH\TO\api\cron.php

      Thank you guys for all the answers, question, Im totally new with osticket, how can I call cron.php from PHP?? Im using xampp, do I need to change the settings on the cron.php file?? or should I take the original cron.php by default on osticket installation??

      step 1 - create a osticket.bat
      put the correct version of this in it:
      PATH\TO\PHP\php.exe -f PATH\TO\api\cron.php
      step 2 - open task scheduler.
      step 3 - have it run the osticket.bat
      step 4 - set the time you want it to run (I run mine every 5 minutes I think)
      step 5 - save.

      Hi ntozier, thanks for your fast reply!! What is an osticket.bat?? How can I create this file?? what I need to put inside that file?? A lot of questions I know haha

      Hi Ntozier, thank you, now Im running osticket.bat through task scheduler, but Im still not receiving tickets through the portal, look this is my cron.php, is this correct? Should I modify this??

      <?php
      /*********************************************************************
      cron.php

      File to handle LOCAL cron job calls.
      
      Peter Rotich <peter@osticket.com>
      Copyright (c)  2006-2013 osTicket
      http://www.osticket.com
      
      Released under the GNU General Public License WITHOUT ANY WARRANTY.
      See LICENSE.TXT for details.
      
      vim: expandtab sw=4 ts=4 sts=4:

      **********************************************************************/
      @chdir(dirname(FILE).'/'); //Change dir.
      require('api.inc.php');

      if (!osTicket::is_cli())
      die(__('cron.php only supports local cron calls - use http -> api/tasks/cron'));

      require_once(INCLUDE_DIR.'api.cron.php');
      LocalCronApiController::call();
      ?>

      ntozier, now mi tickets are working!!! thank you so much!!

      ntozier, one last question, everything seems working fine, the only problem is when I try to create a ticket from the portal it takes like 30 seconds to create the ticket, its really slow, Im think that is something that I changed up because I change a lot of things while I was trying to run Osticket, do you know what this could be??

      @jsbanjo osTicket "pauses" when it tries to send an email. If you are using PHPMail you might want to switch to SMTP. 30s is a really long time though. How do you have osTicket configured for email? PHPmail? SMTP?

        Yes, and the Default MTA at: Admin panel -> Emails -> Settings

          ntozier What do you think about my settings??? do you think that I should change something?? I think that my osTicket is configured through SMTP

          That looks okay other then you should uncheck "Fetch on Auto-cron" since you are running a cron/task scheduler.

          As a side note I went to your web site on two different computers and the load time on your site was over 15s (not your support site, your domain). I'm wondering if you need a heftier webserver than you are currently running if both are hosted on the same web server. I'm also wondering what the ping times between the webserver and the mailserver look like, and how many hops it is via traceroute. I do not see anything that would cause such a delay in the settings.

          Side note it takes us about 5-10 seconds to open a ticket on our system which is an internally hosted webserver and using o365 to send email. We noticed a big jump when we migrated from internally hosted Exchange to O365 Exchange as it was around 1-2 seconds before we migrated.