Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Help! :oops: I'm getting error on several PHP pages that use CouchCMS:

'couch' folder should reside in the main web-site folder


Why might this be happening, and what might I do to resolve the issue?

=====
DETAILS (warning: long)

- The website is PHP-based. It is served by Nginx, behind Varnish cache. (My Varnish process is configured to only serve cached pages to users without any cookies.)

- The site is actually multiple sub-sites, living on a single subdomain:

http://www.example.com/Site1
http://www.example.com/Site2
http://www.example.com/Site3

- Each sub-site has *its own individual CouchCMS installation*, like this:

http://www.example.com/Site1/couch
http://www.example.com/Site2/couch
http://www.example.com/Site3/couch

(I.e., there is no "master" CouchCMS that controls all of the sub-sites.)

- Each individual CouchCMS has its own separate database, e.g.:

Site1 has a database named 'site1' for its Couch data
Site2 has a database named 'site2' for its Couch data
Site3 has a database named 'site3' for its Couch data

- Our publishing workflow requires that edits be made to a "staging" environment, prior to being 'published' to "production". So really, every site has two instances, like this:

http://staging.example.com/Site1 <~ "staging" (CMS edits are made here)
http://www.example.com/Site1 <~ "production" ('site1' database is "pushed" to this server.)

To publish changes, here is what we do: An editor goes to http://staging.example.com/Site1/couch. She makes text changes. She then runs a "publish.php" script, which copies the respective database ('site1') over to http://www.example.com. "Staging" and "production" are two different cloud servers, but they have been built identically: They always have the exact same code for the site. They have the exact same PHP versions. They have the exact same Nginx versions and configurations. They have the exact same ionCube Loaders.

I have never seen this issue on my local machine. I have only seen it on the "production" machine. And it seems to happen *intermittently*.

I can't find anything reference in any of the Couch database tables that may cause this issue.

The only thing that might seem to be related is this line, in couch/config.php:

Code: Select all
//define( 'K_SITE_URL', ...


I've set it to 'http://www.example.com/Site1', but that didn't seem to do anything -- the error still continued to appear intermittently as before.

The only two reasons for this error that I can think of are:

- ??? Varnish cache is somehow interfering with CouchCMS. (But that seems unlikely.)
- ??? There is a hidden configuration in CouchCMS somewhere that references the site's absolute path, and the fact that we "publish" from a "staging" server to a "production" server means that the reference is wrong.
Hi Matthew,

In the two year's that Couch has been around, this is only the second time that I'm coming across this error. The first time around, it was a configuration error on part of the user.
This time though, I think there are other factors at work that are (yet) unknown to me.

See, the way Couch works is that when a template is accessed via browser, it tries to find out the name and the physical path of the template.
The path of Couch's installation is already known and it is expected that the template being accessed will exist somewhere within Couch's parent folder of sub-folders (never outside Couch's parent folder)

e.g. if following is the admin-panel, Site1 is Couch's parent folder
http://www.example.com/Site1/couch

and so the following template path is ok:
http://www.example.com/Site1/contact.php

and so is:
http://www.example.com/Site1/aboutus/contact.php

but following is not:
http://www.example.com/contact.php

I suspect, somehow the reported paths are getting messed up.
Not sure why. What is more intriguing is that, as you reported, it is happening only intermittently and only on some templates.
Perhaps the particular cloud configuration has something to do it (but then your 'staging' server is also a cloud server and does not exhibit this problem).

Ideally, I'd really want to take a look at the problem first-hand but I'm aware your's is a secure setup so that is out of question.

Could you please let me know which version of Couch are you using?
Maybe I'll try and make some coding changes to allow hardcoding template names for such dire cases.

Please let me know.
Thanks
Hi again KK, and thanks for your reply. :)

I just thought of an idea of what might be wrong, but first I'll answer your questions:

it is expected that the template being accessed will exist somewhere within Couch's parent folder of sub-folders (never outside Couch's parent folder)


That ^ is already the case. I'm only using it in the expected fashion AFAIK.

http://www.example.com/Site1/couch <~ works
http://www.example.com/Site1/contact.php <~ intermittent problem
http://www.example.com/Site1/aboutus/contact.php <~ intermittent problem
http://www.example.com/contact.php <~ not CouchCMS-ized, so not an issue

Could you please let me know which version of Couch are you using?


I'm using CouchCMS 1.2.5.

Here's something that I realized might (?) be causing the problem.

-- All of our PHP page files look (roughly) like this:

Code: Select all
  <?php include "../inc/header.php"; // <~ or './inc/header.php', depending on file location ?>
  Page-specific HTML and PHP goes here.
  <?php include "../inc/footer.php"; // <~ or './inc/footer.php', depending on file location ?>


We do this to keep the code somewhat DRY. So:

-- "header.php" actually contains the CouchCMS require:
<?php require_once(dirname(__FILE__).'/../couch/cms.php'); ?>

-- "footer.php" actually contains the CouchCMS invocation:
<?php COUCH::invoke(); ?>

Could the fact that CouchCMS is being require'd and invoked *from within the includes*, rather than from the page file itself, be causing the problem?

Thanks again!
Hi Matthews,

Yes, indeed that could be a possible reason as <?php require_once( 'couch/cms.php' ); ?> is what sets the ball rolling by assuming that cms.php's location is the Couch admin folder. If something at this stage goes awry it would reflect on further assumptions.

I suggest you please place those two required PHP statements directly within the templates.
Do let me know if this helps.

Thanks.
Hi again KK,

Moving the <?php require_once(dirname(__FILE__).'/couch/cms.php'); ?> snippet into the individual template files (instead of including it in the header partial) seems to have helped. I haven't seen the error since.

So, I'll call this one "resolved" for now. 8-)

A brief side-note: I'm starting to suspect that Varnish (a caching reverse HTTP proxy), which I've got running only on the production server, might have something do with the problem. Varnish listens on port 80 and serves cached responses; when there's a cache miss, the request gets sent to port 8080, where the actual backend webserver (in my case Nginx) is listening. This might explain why (a) the error is intermittent and (b) I've only seen the error in production. But that's a wild guess.

Matthew
Hi Matthew,

I'll call this one "resolved" for now. 8-)

Let us hope it stays this way :)
Transient errors are indeed every developer's nightmare.

I don't have much experience with Varnish but I'll try to figure out if the way it works can throw Couch off gear.

Thanks
Hi KK --

A quick follow up re: Varnish, that you might find interesting.

After fixing the previous problem, I started to see another intermittent error:

Code: Select all
Please define your website's URL in config.php


This error would occur every other request. I.e., the first time I'd load /Site1/index.php, I'd the correct page would be served. The second time I'd load it, the error message would be served.

So, as an experiment, I turned off Varnish, changed the Nginx config to listen on the default, port 80. And this immediately resolved the problem.

So, it seems that Varnish cache -- possibly due to the way my particular Varnish process is configured -- interferes with CouchCMS in some way.

Matthew
Thank you for that information, Matthew.
It'll be helpful in trying to locate the exact problem.

BTW, if 'Please define your website's URL in config.php' is the only problem cropping up, I suggest you define the URL in config.php and keep using Varnish.

Thanks.
8 posts Page 1 of 1
cron