function drush_find_tmp

8.0.x drush_find_tmp()
6.x drush_find_tmp()
7.x drush_find_tmp()
4.x drush_find_tmp()
5.x drush_find_tmp()
master drush_find_tmp()

Returns the path to a temporary directory.

This is a custom version of file_directory_path(). We can't directly rely on sys_get_temp_dir() as this path is not valid in some setups for Mac.

Related topics

2 calls to drush_find_tmp()
drush_tempdir in includes/
Creates a temporary directory and return its path.
drush_tempnam in includes/
Creates a temporary file, and registers it so that it will be deleted when drush exits. Whenever possible, drush_save_data_to_temp_file() should be used instead of this function.


includes/, line 1819
The drush API implementation and helpers.


function drush_find_tmp() {
  static $temporary_directory = NULL;

  if (is_null($temporary_directory)) {
    $directories = array();

    // Operating system specific dirs.
    if (substr(PHP_OS, 0, 3) == 'WIN') {
      $directories[] = 'c:\\windows\\temp';
      $directories[] = 'c:\\winnt\\temp';
    else {
      $directories[] = '/tmp';
    // This function exists in PHP 5 >= 5.2.1, but drush
    // requires PHP 5 >= 5.2.0, so we check for it.
    if (function_exists('sys_get_temp_dir')) {
      $directories[] = sys_get_temp_dir();

    foreach ($directories as $directory) {
      if (is_dir($directory) && is_writable($directory)) {
        $temporary_directory = $directory;

    if (empty($temporary_directory)) {
      // If no directory has been found, create one in cwd.
      $temporary_directory = drush_cwd() . '/tmp';
      if (!is_dir($directory)) {
        return drush_set_error('DRUSH_UNABLE_TO_CREATE_TMP_DIR', dt("Unable to create a temporary directory."));

  return $temporary_directory;