You are here

README.txt in Alternative Stream Wrappers 7

WHY MIGHT I NEED ALTERNATIVE STREAM WRAPPERS?
---------------------------------------------

Some hosting configurations with multiple webservers use a mix of 
filesystems local to each webserver and storage which is shared between the 
webs (e.g. using nfs or gluster).

It can sometimes be useful to, for example, use fast local storage for temp
files wherever possible, but shared storage where the webs might need to
share access to the same set of temporary files. 

The views_data_export module is a good example of where shared temp storage
is useful. See: https://drupal.org/node/1782038

This simple module allows Drupal to keep using the built-in stream wrappers 
(e.g. public:// and temporary://) but also have the use of one or more 
Alternative Stream Wrappers for cases like the shared temporary directory.

There may be other uses too - the module aims to be flexible. For example,
if for any reason you want to have more than one public files directory, 
this module should make that possible.


USING ALTERNATIVE STREAM WRAPPERS
---------------------------------

The alt_stream_wrappers_stream_wrappers() function defines a default
alt-temp:// stream wrapper, and this can be used out of the box; all you
need to do is set a value for the variable alt_stream_wrappers_alt-temp_path

e.g.

drush vset alt_stream_wrappers_alt-temp_path '/mnt/nfs/tmp'

If you need more, or different wrappers, you can override the default by
setting a variable, most likely in settings.php

However, there is a caveat; the STREAM_WRAPPER constants have probably not
been defined in time to be used in settings.php so you'll probably need to
use something else to define to the 'type' of each wrapper. One option is to
include the stream_wrappers.inc file like so:

if (!defined('STREAM_WRAPPERS_ALL')) {
  include('./includes/stream_wrappers.inc');
}

..however this module only really provides for two types of wrappers;
public or hidden, so you may want to define these constants (or just use
their integer values) when defining your own wrappers in settings.php

e.g.

define('ALT_STREAM_WRAPPERS_HIDDEN',    13);
define('ALT_STREAM_WRAPPERS_NORMAL',    29);

$conf['alt_stream_wrappers_wrappers'] = array(
    'alt-temp' => array(
      'name' => t('Alternative temporary files'),
      'class' => 'DrupalAltStreamWrapper',
      'description' => t('Alternative temporary local files.'),
      'type' => ALT_STREAM_WRAPPERS_HIDDEN,
    ),
    'foobar' => array(
      'name' => t('Alt public'),
      'class' => 'DrupalAltStreamWrapper',
      'description' => t('Another public file directory.'),
      'type' => ALT_STREAM_WRAPPERS_NORMAL,
    ),
  );
  
Note that the class is always DrupalAltStreamWrapper if you want this module
to take care of actually providing the wrapper class.

In the example above, you'd then need to set a value for the path in
the appropriately named variable e.g.:

$conf['alt_stream_wrappers_foobar_path'] = '/mnt/foo';

File

README.txt
View source
  1. WHY MIGHT I NEED ALTERNATIVE STREAM WRAPPERS?
  2. ---------------------------------------------
  3. Some hosting configurations with multiple webservers use a mix of
  4. filesystems local to each webserver and storage which is shared between the
  5. webs (e.g. using nfs or gluster).
  6. It can sometimes be useful to, for example, use fast local storage for temp
  7. files wherever possible, but shared storage where the webs might need to
  8. share access to the same set of temporary files.
  9. The views_data_export module is a good example of where shared temp storage
  10. is useful. See: https://drupal.org/node/1782038
  11. This simple module allows Drupal to keep using the built-in stream wrappers
  12. (e.g. public:// and temporary://) but also have the use of one or more
  13. Alternative Stream Wrappers for cases like the shared temporary directory.
  14. There may be other uses too - the module aims to be flexible. For example,
  15. if for any reason you want to have more than one public files directory,
  16. this module should make that possible.
  17. USING ALTERNATIVE STREAM WRAPPERS
  18. ---------------------------------
  19. The alt_stream_wrappers_stream_wrappers() function defines a default
  20. alt-temp:// stream wrapper, and this can be used out of the box; all you
  21. need to do is set a value for the variable alt_stream_wrappers_alt-temp_path
  22. e.g.
  23. drush vset alt_stream_wrappers_alt-temp_path '/mnt/nfs/tmp'
  24. If you need more, or different wrappers, you can override the default by
  25. setting a variable, most likely in settings.php
  26. However, there is a caveat; the STREAM_WRAPPER constants have probably not
  27. been defined in time to be used in settings.php so you'll probably need to
  28. use something else to define to the 'type' of each wrapper. One option is to
  29. include the stream_wrappers.inc file like so:
  30. if (!defined('STREAM_WRAPPERS_ALL')) {
  31. include('./includes/stream_wrappers.inc');
  32. }
  33. ..however this module only really provides for two types of wrappers;
  34. public or hidden, so you may want to define these constants (or just use
  35. their integer values) when defining your own wrappers in settings.php
  36. e.g.
  37. define('ALT_STREAM_WRAPPERS_HIDDEN', 13);
  38. define('ALT_STREAM_WRAPPERS_NORMAL', 29);
  39. $conf['alt_stream_wrappers_wrappers'] = array(
  40. 'alt-temp' => array(
  41. 'name' => t('Alternative temporary files'),
  42. 'class' => 'DrupalAltStreamWrapper',
  43. 'description' => t('Alternative temporary local files.'),
  44. 'type' => ALT_STREAM_WRAPPERS_HIDDEN,
  45. ),
  46. 'foobar' => array(
  47. 'name' => t('Alt public'),
  48. 'class' => 'DrupalAltStreamWrapper',
  49. 'description' => t('Another public file directory.'),
  50. 'type' => ALT_STREAM_WRAPPERS_NORMAL,
  51. ),
  52. );
  53. Note that the class is always DrupalAltStreamWrapper if you want this module
  54. to take care of actually providing the wrapper class.
  55. In the example above, you'd then need to set a value for the path in
  56. the appropriately named variable e.g.:
  57. $conf['alt_stream_wrappers_foobar_path'] = '/mnt/foo';