It does seem with the use of file_create_url() that there may be issues using Pressflow D6.22...

The testing advagg does for a CDN base for the 'missing*.css' returns a relative path - and not a absolute.

With the latest advagg *.dev, I now have three places to patch in a relative to absolute URI for this?

eg:

    if (($status == CDN_ENABLED || ($status == CDN_TESTING && user_access(CDN_PERM_ACCESS_TESTING))) && !variable_get(CDN_THEME_LAYER_FALLBACK_VARIABLE, FALSE)) {

      $url_cdn_css = variable_get('my_cdn_css_base_url', '');
      $url_cdn_css .= file_create_url($css_path . $filepath . '.css');
      error_log("advagg css report: " . $url_cdn_css, 0);
      $parts_css = @parse_url($url_cdn_css);
if (file_exists('sites/all/modules/cdn/cdn.module')) {         // if Drupal Module CDN exists
  $my_cdn_css_url = 'http://small.gdlcdn.com/802C5F/cdn1';     // get base CDN url to add to CSS
  $my_cdn_js_url  = 'http://small.gdlcdn.com/802C5F/cdn2';     // get base CDN url to add to JS
  $my_cdn_mapping = $my_cdn_css_url . '|.css'."\n";
  $my_cdn_mapping .= 'http://small.gdlcdn.com/802C5F/cdn2|.js'."\n";
  $my_cdn_mapping .= 'http://small.gdlcdn.com/802C5F/cdn3|.jpg .png .gif .ico'."\n";
  $my_cdn_mapping .= 'http://small.gdlcdn.com/802C5F/cdn4|.pdf'."\n";
  $conf['cdn_basic_mapping'] = $my_cdn_mapping;
  $conf['my_cdn_css_base_url'] = $my_cdn_css_url;
  $conf['my_cdn_js_base_url']  = $my_cdn_js_url;
}

Thoughts?
Easy enough too 'correct' - just requesting others thoughts / expansion on this

See -> http://drupal.org/node/839282

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Peter Bowey’s picture

The above event / description is based on using Wim Leers CDN module project;

http://drupal.org/project/cdn

Notes: The second php code listing (above) is applied in D6's settings.php

Peter Bowey’s picture

Title: Pressflow D6.22 with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow effects drupal_http_request() » Pressflow D6.22 with advagg's use of file_create_url() - CDN
Category: bug » support

See https://bugs.launchpad.net/pressflow/+bug/597718
for content relating to how this new file_create_url() should be integrated into latest Pressflow.

[Changes:] After some research on this D6 file_create_url() use, I find that Drupal's (D6) method is flagged as 'buggy', and that Pressflow has 'corrected' the use (@return) of file_create_url(). Duh *beware* D6 coders...

Hence, Pressflow will not process parameters the 'OLD' D6 way. The returned value @return is not what it was under Drupal D6.

In the current case of 'advagg', this effects the value (URI expected) passed to drupal_http_request().

In my testing, this 'change' effects; Pressflow 6.20 to Pressflow 6.22

Adding Wim Leers 'comment' related to this: -> http://drupal.org/node/839282#comment-3358288

Peter Bowey’s picture

Category: support » bug
calypso2k’s picture

Pressflow 6.22 + CDN (in my configuration three additional domains are pointing to default drupal installation domain as it is devel setup) i've got:


Adv CSS/JS Agg - CDN Async Mode CSS CDN Issue
Check your CDN settings; CSS request is not coming back when routed through the CDN. If you are still having issues you can go to the AdvAgg information tab and select Asynchronous debug info. If creating an issue on d.o be sure to include this information.
Adv CSS/JS Agg - CDN Async Mode JS CDN Issue
Check your CDN settings; JS request is not coming back when routed through the CDN. If you are still having issues you can go to the AdvAgg information tab and select Asynchronous debug info. If creating an issue on d.o be sure to include this information.

I've red links posted by You, but i don't understand.

Can You even remotely point me to what is causing the problem and how can I solve it?

debug:

http://192.168.0.13/ohmygod/sites/default/files/advagg_css/css_missing3685611941306684657_0.css: 
stdClass Object (
    [request] => GET /ohmygod/sites/default/files/advagg_css/css_missing3685611941306684657_0.css HTTP/1.0
Host: 192.168.0.13
User-Agent: Drupal (+http://drupal.org/)

    [data] => <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p><p><a href="/ohmygod/">Home</a></p><!-- advagg_missing_fast404 --></body></html>
    [protocol] => HTTP/1.0
    [status_message] => Not Found
    [headers] => Array (
            [Date] => Sun, 29 May 2011 15:57:37 GMT
            [Server] => Apache
            [X-Drupal-Cache] => MISS
            [Last-Modified] => Sun, 29 May 2011 15:57:37 +0000
            [Cache-Control] => no-cache, must-revalidate, post-check=0, pre-check=0
            [X-AdvAgg] => Failed Validation. Wrong Pattern.
            [Content-Length] => 315
            [Connection] => close
            [Content-Type] => text/html; charset=utf-8
        )
    [error] => Not Found
    [code] => 404
    [timer] => Array (
            [count] => 1
            [time] => 237.53
        )
)

/ohmygod/sites/default/files/advagg_css/css_missing3685611941306684657_0.css: 
stdClass Object (
    [error] => missing schema
    [code] => -1002
    [timer] => Array (
            [count] => 1
            [time] => 0.02
        )
)
Peter Bowey’s picture

Category: support » bug

Refer #4

Yes, I will outline the fix:

Simply, we need to feed advagg a full URI, as the current file_create_url() fails to do this...

The following edits allow this:

Step 1: edit advagg.install and change thus (the + lines)

  // Test CDN module; JS & CSS paths.
  if (module_exists('cdn')) {
    // Make sure CDN module is on.
    $status = variable_get(CDN_STATUS_VARIABLE, CDN_DISABLED);
    if (($status == CDN_ENABLED || ($status == CDN_TESTING && user_access(CDN_PERM_ACCESS_TESTING))) && !variable_get(CDN_THEME_LAYER_FALLBACK_VARIABLE, FALSE)) {

+      $url_cdn_css = variable_get('my_cdn_css_base_url', '') . file_create_url($css_path . $filepath . '.css');   // Append CDN CSS Base
-      $url_cdn_css = file_create_url($css_path . $filepath . '.css');  // remove
      $parts_css = @parse_url($url_cdn_css);
      // Do not test CDN CSS if the hosts are the same.
      if (strcmp($parts_css['host'], $_SERVER['HTTP_HOST']) == 0) {
        $parts_css = FALSE;
      }

+      $url_cdn_js = variable_get('my_cdn_js_base_url', '') . file_create_url($js_path . $filepath . '.js');       // Append CDN JS Base
-      $url_cdn_js = file_create_url($js_path . $filepath . '.js');       // remove
      $parts_js = @parse_url($url_cdn_js);
      // Do not test CDN JS if the hosts are the same.
      if (strcmp($parts_js['host'], $_SERVER['HTTP_HOST']) == 0) {
        $parts_js = FALSE;
      }

      if (!empty($parts_css)) {
        // Send request and also time it.
        timer_start(__FUNCTION__ . 'cdn_css');
        $data_cdn_css = drupal_http_request($url_cdn_css);
        $time_cdn_css = timer_stop(__FUNCTION__ . 'cdn_css');
      }
      if (!empty($parts_js)) {
        // Send request and also time it.
        timer_start(__FUNCTION__ . 'cdn_js');
        $data_cdn_js = drupal_http_request($url_cdn_js);
        $time_cdn_js = timer_stop(__FUNCTION__ . 'cdn_js');
      }
      $mode = variable_get(CDN_MODE_VARIABLE, CDN_MODE_BASIC);
    }
  }

Step 2: Edit advagg.admin.inc and change thus (the + lines)

  timer_start(__FUNCTION__ . 'local');
  $data_local = drupal_http_request($url, $headers);
  $data_local->timer = timer_stop(__FUNCTION__ . 'local');
  list($data, $rows) = advagg_form_print_r($data_local);
  $form['async']['normal'] = array(
    '#type'           => 'textarea',
    '#title'          => check_plain($url),
    '#default_value'  => $data,
    '#rows'           => min($rows+1, 50),
  );

  if (module_exists('cdn')) {
+    $url_cdn = variable_get('my_cdn_css_base_url', '') . file_create_url($filepath);        // Append CDN Base
-    $url_cdn = file_create_url($filepath);        // remove

    // Send request and also time it.
    timer_start(__FUNCTION__ . 'cdn');
    $data_cdn = drupal_http_request($url_cdn);
    $data_cdn->timer = timer_stop(__FUNCTION__ . 'cdn');
    list($data, $rows) = advagg_form_print_r($data_cdn);
    $form['async']['cdn'] = array(
      '#type'           => 'textarea',
      '#title'          => check_plain($url_cdn),
      '#default_value'  => $data,
      '#rows'           => min($rows+1, 50),
    );
  }

  return $form;
}

Step 3: add the following to your active settings.php:

if (file_exists('sites/all/modules/cdn/cdn.module')) {         // if Drupal Module CDN exists
  $my_cdn_css_url = 'http://yourcdnbase.com';     // base CDN url to add to CSS
  $my_cdn_js_url  = 'http://yourcdnbase.com';     // base CDN url to add to JS
  $conf['my_cdn_css_base_url'] = $my_cdn_css_url;
  $conf['my_cdn_js_base_url']  = $my_cdn_js_url;
}

Now the URI will be available for advagg checks.

Notes: The references to 'http://yourcdnbase.com' *need* to be changed for your cdn environment.
The 'yourcdnbase.com' [string] represents the missing 'URI' that file_create_url() fails to return (it returns only a relative path - instead of the URI to the missing 404 file location). We need a 'correct URI' to sent to the advagg drupal_http_request() **This is where the 'missing schema' error -1002 result comes from.** Note: we add the missing 'schema' (http or https).

See above code edits and previous notes on Drupal versus Pressflow use of this function.

Helpful Note: The error status showing:

[error] => missing schema
[code] => -1002

is basically telling us that a incorrect 'URI' was attempted / used. 'schema' refers to the 'http/https' (or lack of it - in this case) to the next called function: drupal_http_request()

Peter Bowey’s picture

Title: Pressflow D6.22 with advagg's use of file_create_url() - CDN » Pressflow D6.22 with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow
Peter Bowey’s picture

Title: Pressflow D6.2x with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow effects drupal_http_request() » Pressflow D6.22 with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow

Lets compare the actual [current] core for Drupal 6 vs Pressflow for file_create_url() (file.inc in /includes)..

1) Pressflow 6.x: file_create_url()
Notes: This comes from the latest Pressflow 6.22 core release

/**
 * Create the download path to a file.
 *
 * There are two kinds of local files:
 * - "created files", i.e. those in the files directory (which is stored in
 *   the file_directory_path variable and can be retrieved using
 *   file_directory_path()). These are files that have either been uploaded by
 *   users or were generated automatically (for example through CSS
 *   aggregation).
 * - "shipped files", i.e. those outside of the files directory, which ship as
 *   part of Drupal core or contributed modules or themes.
 *
 * @param $path
 *   A string containing the Drupal path (i.e. path relative to the Drupal
 *   root directory) of the file to generate the URL for.
 * @return
 *   A string containing a URL that can be used to access the file.
 */
function file_create_url($path) {
  // Clean up Windows paths.
  $old_path = $path = str_replace('\\', '/', $path);

  drupal_alter('file_url', $path);

  // Return path if it was altered by any module, or if it already is a
  // root-relative or a protocol-relative URL.
  if ($path != $old_path || drupal_substr($path, 0, 1) == '/' || drupal_substr($path, 0, 2) == '//') {
    return $path;
  }

  // Shipped files.
  if (preg_match("#^(/?)(misc|modules|sites|themes)/#", $path) && (strpos($path, file_directory_path() . '/') !== 0)) {
    return base_path() . $path;
  }
  // Created files.
  else {
    switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
      case FILE_DOWNLOADS_PUBLIC:
        return base_path() . $path;
      case FILE_DOWNLOADS_PRIVATE:
        // Strip file_directory_path from $path. Private downloads' URLs are
        // rewritten to be served relatively to system/files (which is a menu
        // callback that streams the file) instead of relatively to the file
        // directory path.
        if (strpos($path, file_directory_path() . '/') === 0) {
          $path = trim(substr($path, strlen(file_directory_path())), '\\/');
        }
        return url('system/files/' . $path, array('absolute' => TRUE));
    }
  }
}

2) Drupal 6.x: file_create_url()

function file_create_url($path) {
  // Strip file_directory_path from $path. We only include relative paths in urls.
  if (strpos($path, file_directory_path() . '/') === 0) {
    $path = trim(substr($path, strlen(file_directory_path())), '\\/');
  }
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return $GLOBALS['base_url'] . '/' . file_directory_path() . '/' . str_replace('\\', '/', $path);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/' . $path, array('absolute' => TRUE));
  }
}

* With Pressflow, the base_path() call in file_create_url() comes back as "/". *

Peter

Peter Bowey’s picture

Title: Pressflow D6.22 with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow » Pressflow D6.22 with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow effects drupal_http_request()
Peter Bowey’s picture

Title: Pressflow D6.22 with advagg's use of file_create_url() - CDN » Pressflow D6.2x with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow effects drupal_http_request()
calypso2k’s picture

many, many thanks for Your help :)

I've made bug report @ pressflow
https://bugs.launchpad.net/pressflow/+bug/790092

mikeytown2’s picture

Title: Pressflow D6.22 with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow » Pressflow D6.2x with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow effects drupal_http_request()
FileSize
1.23 KB

@calypso2k
there is a second field set on that debug page; for your case that is what we are after... I need to change that note to let people know there are 2 if you have the CDN module installed. Patch below fixes that notice; which has been committed.

mikeytown2’s picture

Figured out the issue... it's not that complicated. Has to do with cdn_file_url_alter

define('CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE', 'cdn_exception_drupal_path_blacklist');
define('CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_DEFAULT',  'admin*');

...

  variable_get(CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_VARIABLE, CDN_EXCEPTION_DRUPAL_PATH_BLACKLIST_DEFAULT);

...

    // If the current Drupal path matches one of the blacklisted Drupal paths,
    // return immediately.
    if (drupal_match_path($_GET['q'], $drupal_path_blacklist)) {
      return;
    }

Looks like when I test this I need to do a variable get; and scrub admin* from the list, just for this page.

mikeytown2’s picture

Status: Active » Fixed
FileSize
1.75 KB

Hopefully this fixes this issue; it has been committed.

@peter bowey
This should take care of some of the hacks you had to do to advagg.

mikeytown2’s picture

Title: Pressflow D6.2x with advagg's use of file_create_url() - CDN *code changes* Drupal vs Pressflow effects drupal_http_request() » cdn_file_url_alter's path blacklist by default has admin*. AdvAgg CDN tests on status page not working as a result.
Peter Bowey’s picture

@mikeytown2

Hmm, interesting .....

Wim Leers (via cdn module), defines this 'default'; define('CDN_EXCEPTION_FILE_PATH_BLACKLIST_DEFAULT', "*.js\n*/image_captcha/*");

I had (previously) set the CDN blacklist to ONLY "*/image_captcha/*

I note that the patch (#13 above) only deals with the CDN blacklist 'default'??

@mikeytown2, I will test new advagg.git 'patch' - later today!

Peter Bowey’s picture

Refer #13

@mikeytown2
The only advagg 'hack' I should need is the single (1) for 'prefixing' my special CDN URI case-> 'http://small.gdlcdn.com/802C5F/cdn1' as I choose to not use domain name references (like small.gdlcdn.com.

I like avoiding the millisecond lag of using CDN 'CNAMES'. I have bench-marked it to be very small with Edgecast CDN use - about 10-18ms :)

So this 'custom' prefix / method is not a coding 'concern' for advagg...

David Strauss’s picture

Subscribing. Anyone have a good idea how I can improve Pressflow compatibility with Drupal behavior here?

Peter Bowey’s picture

Refer #17

@David Straus, I have outlined the Pressflow advagg method at #5.

See http://drupal.org/node/1172012#comment-4532666

It works great! (Spent a lot of time testing this)

Notes: I have *not yet* tested the new advagg.git patch submitted @ #13 -> http://drupal.org/node/1172012#comment-4541260

Update: Just tested #13 -> http://drupal.org/node/1172012#comment-4541260
It works!

Peter Bowey’s picture

*Solved*

Just tested #13 -> http://drupal.org/node/1172012#comment-4541260

The latest *.dev advagg.git solves this issue with Pressflow!

Good News for Pressflow advagg users!

Report Status shows:

Adv CSS/JS Agg - Asynchronous Mode	Already set to TRUE
Adv CSS/JS Agg - CDN Async Mode	JS CDN
Requests through the CDN are getting back to advagg for JS files.
Adv CSS/JS Agg - CDN Async Mode	CSS CDN
Requests through the CDN are getting back to advagg for CSS files.
Adv CSS/JS Agg - Socket Timeout	Already set to 1 seconds. Raw timer: 62.95
AdvAgg JS Compress - Callback	The callback is working correctly.

Thanks mikeytown2 :)

David Strauss’s picture

I've reverted the change to file_create_url() in the latest Pressflow trunk, which should be accessible in Bazaar and git immediately and as a tarball within 24 hours (as Pressflow 6.22.104).

Now, back to figuring out how to solve the problem of pages being cached with absolute HTTP (not HTTPS) URLs for assets when the page gets served with HTTPS. Solving that was the original reason I modified file_create_url() to be more relative.

mikeytown2’s picture

@David Strauss
The issue here had nothing to do with pressflow. Sorry that you where alerted to this issue. The code that shipped with 6.22 works great.

Peter Bowey’s picture

Refer #21 -> http://drupal.org/node/1172012#comment-4542992
@mikeytown2

Would be good if you did explain how the above 'issue' come to exist.

I was one of at least two Pressflow users that noticed this 'advagg bug'. Did you get any 'bug reports' from the many Drupal users (not using Pressflow)?

mikeytown2’s picture

On all of our sites we do not have any blacklisted CDN paths; discovered the root of this bug when I did a fresh install. I was expecting file_create_url to always pass an absolute URL if the CDN module is installed.

Peter Bowey’s picture

See this Pressflow bug report link for related 'issues' effected by the CDN module:
https://bugs.launchpad.net/pressflow/+bug/729783 (David Strauss wrote on 2011-05-31)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Jaypan’s picture

Version: 6.x-1.x-dev » 6.x-1.6

I'm seeing this issue with Pressflow 6.24, advagg 6.x-1.6, and CDN 6.x-2.3. Is there something I can show here to help debug the issue?