Custom module stopped executing after 30 seconds I've written a custom module that adds many users from a database to drupal database. So, it has many database queries to take care of the drupal tables: users, user_roles, url_alias, profile and field_data_field_$fieldname and field_revision_field_$fieldname where $fieldname is the profile2 field and has many such fields.

The problem is when I execute this module (the trigger is user selects an option in the form which is specific for this module), it executed for only 30 seconds and inserted some 20+ users where I have to insert 500+ users. After 30 seconds, it didn't display any error. It stayed on the same form.

How can I clear this?
You need write batch operation:


  Functions allowing forms processing to be spread out over several page
  requests, thus ensuring that the processing does not get interrupted
  because of a PHP timeout, while allowing the user to receive feedback
  on the progress of the ongoing operations.


http://api.drupal.org/api/drupal/includes%21form.inc/group/batch/7