cURL cronjobs

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • cURL cronjobs

      to use cronjobs via php-curl

      first make a php-file and insert

      PHP Source Code

      1. <?php
      2. $ch = curl_init();
      3. curl_setopt($ch, CURLOPT_URL, '');
      4. curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
      5. curl_setopt($ch, CURLOPT_POST, true);
      6. curl_setopt($ch, CURLOPT_POSTFIELDS, "username=crondo&password=croncron&uni=1");
      7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      8. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
      9. curl_setopt($ch, CURLOPT_COOKIEJAR, '');
      10. curl_setopt($ch, CURLOPT_COOKIEFILE, '');
      11. $answer = curl_exec($ch);
      12. curl_setopt($ch, CURLOPT_URL, '');
      13. curl_setopt($ch, CURLOPT_POST, false);
      14. curl_setopt($ch, CURLOPT_POSTFIELDS, "");
      15. $answer = curl_exec($ch);
      Display All
      change 'crondo' and 'croncron'
      change '' to the url of your game

      now open cronjob.php
      add this

      PHP Source Code

      1. if($cronjobID == '111'){
      2. foreach($cronjobsTodo as $value) {
      3. Cronjob::execute($value);
      4. }
      5. exit;
      6. }

      PHP Source Code

      1. $cronjobsTodo = Cronjob::getNeedTodoExecutedJobs();

      now make a cronjob
      in console you can use crontab -e
      cron can look like this(depends on filename and php-path)

      Source Code

      1. * * * * * /usr/bin/php /var/www/yourgame/yourfile.php >/dev/null 2>&1

      now go to styles/templates/layout-full.tpl and delete following line

      PHP Source Code

      1. {foreach $cronjobs as $cronjob}<img src="cronjob.php?cronjobID={$cronjob}" alt="">{/foreach}
      finaly you can check if it is functioning by having a look into the uni1_cronjobs_log table, and see if they are used

      curl can also be used as cron directly without php.

      ps. make a user wich can log in the game
      the script is logging in an existing account and running the cronjobs wich would be triggert by a user.
      by this the crons keep configuratable in the adminmenu and there is only one cron needed to organize them all.
    • Interesting snippet. Since the cronjobs only runs when one user does "clicks" on the game.
      Looking for good VPS to host your game? Use DigitalOcean and get 100$ bonus credit for 2 months!

      Private project -

      I can build any mod. Need my service? Contact me via PM
    • the usercrons are not accurat.
      i have auctions in my game wich have to trigger at a precise time.

      it was a bit tricky to trigger the 2moonscrons by a servercron(session), so i thought it could be very useful for others to save time :)
    • @zombi87 you just need to follow the guide, if you have a required cron mod such auctions, bots, asteroids event... also you need to be able to manage the server in order to setup crontabs (well, cpanel does this for who is hosting for the game?)
      Looking for good VPS to host your game? Use DigitalOcean and get 100$ bonus credit for 2 months!

      Private project -

      I can build any mod. Need my service? Contact me via PM
    • Maybe add a whitelist ip to be sure the request come from the server and not from someone else ?

      also maybe/maybe not, instead of creating a new account and reduce de curl calls, wasnt it easier for example to copy cronjob.php to cronCurl.php and remove the is session validate code ? This avoid the fact to need an user to do the cron.

      - Xterium Template
      - War of Alliance Template
      - Antaris-Legacy Template
      - Ogame Template

      I can and will only help with instalation with hostings including cpanel or plesk and an teamviewer access

      The post was edited 1 time, last by Thisishowwedoit ().