You are here

function devel_query_put_contents in Devel 7

Writes the variables information to a file.

It will be retrieved on demand via AJAX.

1 call to devel_query_put_contents()
devel_shutdown_query in ./devel.module
Returns the rendered query log.

File

./devel.module, line 1275
This module holds functions useful for Drupal development.

Code

function devel_query_put_contents($queries) {
  $request_id = mt_rand(1, 1000000);
  $path = "temporary://devel_querylog";

  // Create the devel_querylog within the temp folder, if needed.
  file_prepare_directory($path, FILE_CREATE_DIRECTORY);

  // Occassionally wipe the querylog dir so that files don't accumulate.
  $range = variable_get('devel_query_random_range', 1000);
  if (mt_rand(1, $range) == 1) {
    devel_empty_dir($path);
  }
  $path .= "/{$request_id}.txt";
  $path = file_stream_wrapper_uri_normalize($path);

  // Save queries as a json array. Suppress errors due to recursion ()
  file_put_contents($path, @json_encode($queries));
  $settings['devel'] = array(
    // A random string that is sent to the browser.
    // It enables the AJAX to retrieve queries from this request.
    'request_id' => $request_id,
  );
  print '<script type="text/javascript">jQuery.extend(Drupal.settings, ' . json_encode($settings) . ");</script>\n";
}