3

Drupal's Background Process module has been suggested as an alternative to Cron and Batch when heavy lifting is required. The API documentation on background process is good but does not go into details on how it actually works and its' limitations. Can someone explain how Background Process gets around the PHP timeout issue and keeps tasks alive - and whether it operates efficiently (e.g. vs. Batch).

Thank you!

  • 2
    By timeout do you mean the max_execution_time setting? If so I think the answer is that it doesn't - Background Process uses stream_socket_client() to dispatch potentially parallel/non-blocking requests to Drupal URLs; once those requests are received they're still governed by your normal PHP settings as far as I know. – Clive Apr 18 '13 at 16:59
  • @Clive I believe max_execution_time is the one. Interesting, so what does background process do when it needs to process multiple items in serial? (for instance in the example on the bg process page background_process_start_locked('dontrunconcurrently', 'mymodule_dosomething', $myvar1, $myvar2);) – Toaster Apr 18 '13 at 17:16
  • 1
    That function doesn't seem to do anything different except pass a handle string to the BackgroundProcess class (otherwise 'auto' is used). That will likely be used to track a particular request by name. For the http request stuff you want to be looking at the background_process_http_request(), background_process_http_request_initiate() and background_process_http_request_get_response() functions in the main module file. With a bit of cross-referencing to the stream_socket_client() docs it should all become clear :) – Clive Apr 18 '13 at 17:33
2

Background Process uses set_time_limit() to control the timeout of the subrequest. It defaults to 0 (php script does not time out, i.e. runs indefinitely).

  • background_process_start_locked('dontrunconcurrently', 'mymodule_dosomething', $myvar1, $myvar2);

This should be used when you want to ensure that your background process wont run concurrently with itself. In reality the "dontrunconcurrently" is used as a key for a lock.

Background Process has no internal mechanism per se to control serial execution of background processes.

For serial execution of background processes you could take a look at Background Batch, which allows you to run standard Drupal batch jobs as background processes, or you could maintain a state within your background process function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.