Answers.Body: <p>If you run the schedulded job as a cron job and don't use the http-method for the <a href="https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/#commands" rel="nofollow noreferrer">setup</a> you will not face a <a href="http://php.net/manual/en/info.configuration.php#ini.max-execution-time" rel="nofollow noreferrer">php runtime timeout</a>. We did have no issues with schedulded jobs running multiple hours.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-22T14:43:28.440Z
Answers.Text: Thanks I used `set_time_limit(0);` at the beginning of the scheduled job code.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-22T12:43:52.393Z
Answers.LastActivityDate: 2018-05-22T12:43:52.393Z
Answers.UserDisplayName: Thomas Schüttler
Body: <p>In the Areas extension (<a href="https://lab.civicrm.org/extensions/org.civicoop.areas" rel="nofollow noreferrer">https://lab.civicrm.org/extensions/org.civicoop.areas</a>) an administrator can define areas such as West Coast and a contact living in a city in West Coast is linked to the area West Coast. </p>
  
  <p>Every time an address is updated the linked areas of that contact is also updated. </p>
  
  <p>However we need to have a solution for the use case when an administrator adds or changes an existing Area. </p>
  
  <p>My idea is that a cron job runs every day and queries the contact table and checks contact for contact the linked areas. This would probably work fine a small database but I am worried that this job times out in a large database.</p>
  
  <p>How would a solution look like if the database has for example 1.000.000 records? </p>
  
Tags: <developer><cron-job><cron>
Title: Long running Scheduled Job
ThreadText: # Long running Scheduled Job
  
  (Asked by: username_0 on 2018-05-22)
  
  In the Areas extension (<https://lab.civicrm.org/extensions/org.username_0.areas>) an administrator can define areas such as West Coast and a contact living in a city in West Coast is linked to the area West Coast.
  
  Every time an address is updated the linked areas of that contact is also updated.
  
  However we need to have a solution for the use case when an administrator adds or changes an existing Area.
  
  My idea is that a cron job runs every day and queries the contact table and checks contact for contact the linked areas. This would probably work fine a small database but I am worried that this job times out in a large database.
  
  How would a solution look like if the database has for example 1.000.000 records?
  
  **Tags:** developer, cron-job, cron
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-22. Score: 3 | Accepted answer
  
  If you run the schedulded job as a cron job and don't use the http-method for the [setup](https://docs.civicrm.org/sysadmin/en/latest/setup/jobs/#commands) you will not face a [php runtime timeout](http://php.net/manual/en/info.configuration.php#ini.max-execution-time). We did have no issues with schedulded jobs running multiple hours.
  
  > **Comments:**
  > **username_0**: Thanks I used `set_time_limit(0);` at the beginning of the scheduled job code.  
  
  ---
  
  