Running asynchronous PHP code I have Drupal server with a REST API using services and rest_server (that's just background, I don't THINK that applies to this problem at all.) I'd like particular API calls to only report back that the request was received, but then go on to do further work in PHP.

To me, this seems like a thread/fork solution, but I can't seem to find a viable solution using PHP/Drupal. The first (and from the looks of it, easiest) thing I came across was the pcntl_fork() function. But, as it looks like that's not viable:


  It is not possible to use the function 'pcntl_fork' when PHP is used
  as Apache module. You can only use pcntl_fork in CGI mode or from
  command-line.
  
  Using this function will result in: 'Fatal error: Call to undefined
  function: pcntl_fork()'


(And, indeed, when I try using function_exists() through command line, it's there, but when run in PHP through Drupal it says function is undefined. I'm reading some stuff on how to install it/recompile PHP with it, but would prefer if there were a method that didn't involve changes to the server.)

Other than that, I'm coming across solutions such as creating a queue to run with cron jobs, creating convoluted menu items, or a whole background processes... thing. All I want is for some arbitrary code to be run off on its own. Does anyone have a suggestion that they feel works best with with Drupal?

(Also, I don't know what to tag this as--I tried thread or asynchronous but those don't seem to exist--so feel free to tag.)
A request to a REST API should just return required data and end. If you want to do asynchronous tasks do not reuse request threads, use cron tasks.

If you want to get independent from Durpal cron use your own drush command executed by a system cron. So, you declare a drush command that makes whatever asyncrhonous tasks and then declare a system cron that runs drush on that command.

If you need to prepare data for that command (for example, if some REST API functions generates data that must be processed asynchronously) you can use Drupal Queues. When the API is called add a new element to a certain queue that will be later processed by the drush command.