Running cron without crontab I want code to be executed every n minutes. I know there is a way to run cron in Drupal with crontab but in my case it runs every 3 hours.

What would be the best way to achieve this without using crontab? Can I execute code every time a user opens the first page?
The simplest solution would be to set the cron to run more frequent: every 3 minutes is not unheard of.

However, many modules, including core, do not have a timecheck: they run their code regardless of how long it was since they last ran it. Other modules (also many core) have some "run only every X" implemented. 

You will see an impact, but depending on your specific situation, that may, or may not be a problem.

Once that is done, you can implement hook_cron(): 

function yourmodule_cron() {
  $last_run = variable_get('mymodule_cron_last_run', REQUEST_TIME);

  if ($last_run &lt;= (now() - 180)) {//180 seconds is three minutes. 
    # DO SOMETHING EPIC!
    variable_set('mymodule_cron_last_run', REQUEST_TIME); 
  }
}


If, however, you cannot run cron this often, you may want to write a cron bypass. In Drupal 6, the route would be, to create a menu-item, with a "secret" token in it (to avoid external folks from hitting that URL by accident/to overlad your server). In Drupal 7 there are (not well documented, AFAIK) methods to create thin requests: my code below will bootstrap an entire Drupal, while you may need only a very simple database-query to be ran without accessing any Drupal resources or APIs.

/**
 * Implementation of hook_menu().
 */
function mymodule_menu() {
  $items = array();

  $items['yourmodule/cron/s0mes3cr3tkey'] = array(
    'title'            =&gt; 'not used',
    'description'      =&gt; 'not used',
    'page callback'    =&gt; 'yourmodule_do_epic_stuff',
    'type'             =&gt; MENU_CALLBACK,
  );

  return $items;
}

/** 
 * Menu Callback that does epic stuff.
 */
function _mymodule_do_epic_stuff() {
  # Do Epic Stuff.
}


You can then add an additional crontab to call only that url. 

It is a very bad idea to run such code in the request of a user:


You don't know if users are visiting every 3 minutes. Even if you have 1000visitors per minute, there are potential situations where no user visits for, say 10 minutes.
You don't want your users to be bothered with maintainance code you run in their request. 
You don't want your users to experience faults or errors in your cron-tasks. These tasks can, e.g. check whether some external API is up or down and throw errors on network trouble and such.