CMSMS doesn't treat virtual() as expected

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
chuck
Forum Members
Forum Members
Posts: 23
Joined: Mon Mar 31, 2008 6:33 am

CMSMS doesn't treat virtual() as expected

Post by chuck »

Hello,
I should probably preface this by saying that I really like many of the things about CMSMS.
I'm hoping that I will be able to convert all of our web sites to CMSMS. But I'm really having
difficulties in a couple of areas.
I have one site that has many online tools. Many are written in perl. The simpler ones could
be rewritten in PHP. But as PHP has always handled them perfectly, I have no reason to think
that I need to. CMSMS on the other hand, is not dealing with them, as PHP does.
I'll use the simplest example; a text counter. With PHP, executing a perl script is simply a
matter of: . This has always worked
without fail in PHP. I can also use this same method with pages that contain perl scripts
with PHP: BUT, if I use this
same method with CMSMS ( {php} virtual('counter.pl'); {/php} ).
CMSMS complains about cannot modify headers, headers already sent.
Even though CMSMS complains, the counter still works. I have another very large, and
complex perl program that cannot be converted to PHP. So if CMSMS cannot deal
with perl correctly, using CMSMS will not be an option. :(
I should also note that I made a UDT tag to execute the counter. But CMSMS made the same
complaint. Has anyone successfully used perl scripts with CMSMS? Does anyone have
any possible solutions for the problem I'm having?

Thank you in advance, for your time and trouble.

Chuck

PHP 4-current
Apache-current
CMSMS-1.24
PHP 4-current
Apache-current
CMSMS-1.24
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: CMSMS doesn't treat virtual() as expected

Post by calguy1000 »

it's probably a problem with your perl scripts outputting strings that shouldn't be output and are irrelevant to the task your trying to achieve.

try seing the results of the perl script without a php wrapper... and checking them in view source or in the web developers toolkit, etc.  there's probably something happening that you don't understand.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
chuck
Forum Members
Forum Members
Posts: 23
Joined: Mon Mar 31, 2008 6:33 am

Re: CMSMS doesn't treat virtual() as expected

Post by chuck »

Hello Calguy1000, and thank you for your fast response. :)

I'm not sure I understand your reply. Perhaps my explanation needs to be better. :)
OK here's the scoop; Again, I'll use the simple perl script counter as an example.
The counter has worked flawlessly for years. I use it like so in an .shtml file:

No errors are ever emited, counter works perfectly.
When I changed all of our pages to PHP, I used the following line to run the counter
in the PHP pages:

Again, everything worked as expected - no errors emited, counter worked perfectly.
Now, when I attempt to use the counter in CMSMS pages, I use the following
to run the counter:
{php}virtual('/cgi-bin/counter.pl');{/php}
But CMSMS vomits error messages to the PHP error log -

Code: Select all

Cannot modify header information - headers already sent by...
However, in spite of the error emited, the counter works.  ???
So. IMHO, it appears that CMSMS is not handling perl scripts in the same fashion
that PHP does. Is this correct?
For the sake of argument, here is the counter script:

Code: Select all

#!/usr/bin/perl -Tw
#
#####################################################
##############[ EDIT as REQUIRED ]###################

$number_of_digits = "8";
$end = ".gif";

$pathtocounter = "/usr/local/www/log/counters";
$pathtoimages = "/digits/aaa/";

$graphics = "yes";

##########[ NO EDITING REQUIRED BELOW THIS ]##########
######################################################

# HEAD Statement
# can also be print ("\n");
print ("Content-type: text/html\n\n");

# Find the counter file

open (COUNTER, "$pathtocounter");
$count = <COUNTER>;
chop ($count) if $count =~ /\n$/;
close (COUNTER);

# Add 1

$count += 1;

open (COUNTER, ">$pathtocounter");
print COUNTER ("$count");
close (COUNTER);

@digits = split(//, $count);

if ($number_of_digits eq "") {
        $howmany = @digits;
} else {
        $howmany = $number_of_digits;
}

# Validate statement

$spline = '%0' . $howmany . 'd';
$count = sprintf("$spline", $count);

@digitimages = split(//, $count);

# Display results

foreach $digitimage (@digitimages) {
	if ("$graphics eq yes") {
        $image = "<img src=$pathtoimages" . "$digitimage" . "$end>";
	print ("$image");
	} else {
        $plain = $digitimage;
 	print ("$plain");
	}
}

exit;
Hope this helps. Thank you again for your time and trouble.

Chuck

PHP 4-current
Apache-current
CMSMS-1.24
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: CMSMS doesn't treat virtual() as expected

Post by Nullig »

Have you tried changing:

Code: Select all

# HEAD Statement
# can also be print ("\n");
print ("Content-type: text/html\n\n");
to:

Code: Select all

# HEAD Statement
# can also be print ("\n");
print ("\n");
Nullig
Last edited by Nullig on Sat Apr 05, 2008 12:29 am, edited 1 time in total.
chuck
Forum Members
Forum Members
Posts: 23
Joined: Mon Mar 31, 2008 6:33 am

Re: CMSMS doesn't treat virtual() as expected

Post by chuck »

Hello Nullig, and thank you for your response. :)

Yes, of course. Perhaps you noticed that I mentioned that on the line right above the print statement:

Code: Select all

# can also be print ("\n");
print ("Content-type: text/html\n\n");
:)
In your defense, I didn't mention that I wrote this perl counter. :)

Anyway, to clarify; I tried both:
print ("Content-type: text/html\n\n");
and
print ("\n");
But CMSMS still emits the error to the PHP error log. :(
I should also probably mention that I made a UDT {simplecounter}:

Code: Select all

<?
//Simple perl counter script
virtual('/cgi-bin/counter.pl');
?>
Inserting the tag in the desired location of the CMSMS page also causes CMSMS to emit
the error message to the PHP error log. :(

Thanks again for your response.

Chuck

PHP 4-current
Apache-current
CMSMS-1.24
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: CMSMS doesn't treat virtual() as expected

Post by Nullig »

Have you tried this workaround for your UDT:

Code: Select all

<?
//Simple perl counter script
echo " ";
virtual('/cgi-bin/counter.pl');
?>
Nullig
chuck
Forum Members
Forum Members
Posts: 23
Joined: Mon Mar 31, 2008 6:33 am

Re: CMSMS doesn't treat virtual() as expected

Post by chuck »

Nullig wrote: Have you tried this workaround for your UDT:

Code: Select all

<?
//Simple perl counter script
echo " ";
virtual('/cgi-bin/counter.pl');
?>
Nullig
LOL! Yes I did. But it didn't work either.
Sorry. I guess I should have mentioned that already.

Thanks for taking the time to respond Nullig.

Chuck

P.S. Love your icon. Looks great. :)

Last edited by chuck on Sat Apr 05, 2008 4:49 am, edited 1 time in total.
PHP 4-current
Apache-current
CMSMS-1.24
Wiedmann
Forum Members
Forum Members
Posts: 233
Joined: Wed Mar 26, 2008 1:49 am

Re: CMSMS doesn't treat virtual() as expected

Post by Wiedmann »

chuck wrote:With PHP, executing a perl script is simply a matter of: . This has always worked without fail in PHP. CMSMS complains about cannot modify headers, headers already sent.
virtual() does not work correctly with CMSMS, because Apache flush's the output buffer, output the content of the file, and then return to PHP (PHP can't controll the output buffer if you use virtual()). Every header() that CMSMS want set after virtual(), does not work.

You have two choices:

a) in your template use:

Code: Select all

{fetch file='http://example.com/cgi-bin/counter.pl'}
b) if you don't want use hardcoded servernames, or want use relative paths (like with virtual()), you can add this UDT
php_virtual

Code: Select all

if (!isset($params['uri'])) {
    return;
}

$config    =& $GLOBALS['gCms']->getConfig();
$cms_uri   =  parse_url($config['root_url']);
$param_uri =  parse_url($params['uri']);

$uri  = (isset($param_uri['scheme']) ? $param_uri['scheme'] : $cms_uri['scheme']).'://';
$uri .= isset($param_uri['user']) ? $param_uri['user'] : '';
$uri .= (isset($param_uri['user']) && isset($param_uri['pass'])) ? ':'.$param_uri['pass'] : '';
$uri .= isset($param_uri['user']) ? '@' : '';
$uri .= isset($param_uri['host']) ? $param_uri['host'] : $cms_uri['host'];
$uri .= (0 !== strpos($param_uri['path'], '/')) ? $cms_uri['path'].'/'.$param_uri['path'] : $param_uri['path'];
$uri .= isset($param_uri['query']) ? '?'.$param_uri['query'] : '';

$old_timeout = ini_set('default_socket_timeout', '10');
readfile($uri);
ini_set('default_socket_timeout', $old_timeout);
and in your template:

Code: Select all

{php_virtual uri='/cgi-bin/counter.pl'} 
chuck
Forum Members
Forum Members
Posts: 23
Joined: Mon Mar 31, 2008 6:33 am

Re: CMSMS doesn't treat virtual() as expected

Post by chuck »

SWEET!!!
I really appreciate your taking the time to respond with this invaluable information Wiedmann - really.
I have a very large perl application that I built back in the late '90's that many orginations have come to depend on, on
a daily basis (nasa.gov, for one). I have spent the entire past three days trying to figure a way to make perl and CMSMS
"play nice" together. Only last night, I finally decided that until I was able to work this out, I'd need to resort to DHTML. I
wrote a layering system that wrote the output of my application to a DOM layer. A fair amount of JavaScript that I did
not want to depend on. But it worked, and didn't prevent me from offering my perl application until I could discover
the difference in perl handling between PHP, and CMSMS. I hadn't figured that Apache would be the culprit. As I
primarily run PHP as an Apache module (though not without exception). So I simply assumed CMSMS used/
hadnled PHP in much the same way I already did. How 'bout that! Really. You have no idea how grateful I am that
you were kind enough to take the time to share this information. Thank you Wiedmann.
Your contribution is very good news. :)

All the best to you.

Chuck

PHP 4-current
Apache-current
CMSMS-1.24
chuck
Forum Members
Forum Members
Posts: 23
Joined: Mon Mar 31, 2008 6:33 am

Re: CMSMS doesn't treat virtual() as expected

Post by chuck »

Hello,
Well, that eliminated the Header output error messages. The counter works as it always used to (correctly).
Now, all I need to do is figure out how to keep the output of my large perl application inside CMSMS.
{php_virtual} presents the page right where it belongs in CMSMS. But the output of the perl application
becomes the top page (is not presented in CMSMS). I'll have to take a closer look at how to
keep it in CMSMS.
Perhaps there is some information somewhere for CMSMS on this. Otherwise, I'll have to probably cobble
up some code to get the output to stay in CMSMS.

Thank you again for your input, Wiedmann.

Chuck

PHP 4-current
Apache-current
CMSMS-1.24
Post Reply

Return to “CMSMS Core”