FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Simple PHP script - VMS problem
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Simple PHP script - VMS problem [message #175819] Thu, 27 October 2011 14:39 Go to next message
Pygmalion is currently offline  Pygmalion
Messages: 2
Registered: October 2011
Karma: 0
Junior Member
I have simple PHP counting script, that works perfectly under linux/
unix. It is called using counter.php?Identifier=introduction, than it
reads counter.txt, which looks like
index = 55
introduction = 5
animals = 4
increases introduction to 6 and writes counter.txt. When used in VMS,
it only writes down the first line
index = 55.

I guess the problem is in lines
while (list($Key, $Value) = each($CArr))
{
$tmp = sprintf("%s = %d\n", $Key, $Value);
fwrite($fp, $tmp);
}
which I think does not work properly in VMS. Any idea how to solve
the problem? The whole script is below.

<?php

// get environment
$query_string = getenv("QUERY_STRING");

// parse environment
// split query-string

if(strstr($query_string,"&amp;"))
{$env_array = split("&amp;", $query_string);}
else
{$env_array = split("&", $query_string);}

// split in key=value and convert %XX
while (list($key, $val) = each($env_array))
{
// split
list($name, $wert) = split("=", $val);

// replace %XX by character
$name = urldecode($name);
$wert = urldecode($wert);

// write to $cgivars
$CGIVars[$name] = $wert;
}

if ($CGIVars["Identifier"] <> "")
{
// read counter-file
if (file_exists("counter.txt"))
{

$fp = fopen("counter.txt", "rt");
while ($Line = fgets($fp, 999))
{
// split lines into identifier/counter
if (ereg("([^ ]*) = *([0-9]*)", $Line, $tmp))
{
$CArr["$tmp[1]"] = $tmp[2];
}
}

// close file
fclose($fp);

// get counter
$Counter = $CArr[$CGIVars["Identifier"]];
$Counter += 1;
$CArr[$CGIVars["Identifier"]] = $Counter;
}
else
{
// the new counter is initialized with 1
$CArr[$CGIVars["Identifier"]] = 1;
$Counter = 1;
}

// write counter file
$fp = fopen("counter.txt", "wt");

// output array elements
reset($CArr);
while (list($Key, $Value) = each($CArr))
{
$tmp = sprintf("%s = %d\n", $Key, $Value);
fwrite($fp, $tmp);
}

// close file
fclose($fp);

$Counter = sprintf($Counter);

echo $Counter;
}
?>
Re: Simple PHP script - VMS problem [message #175820 is a reply to message #175819] Thu, 27 October 2011 14:49 Go to previous messageGo to next message
Pygmalion is currently offline  Pygmalion
Messages: 2
Registered: October 2011
Karma: 0
Junior Member
I just figure out that it might just as well be a read problem (reads
only first line or reads all lines as one):

while ($Line = fgets($fp, 999))
{
// split lines into identifier/counter
if (ereg("([^ ]*) = *([0-9]*)", $Line, $tmp))
{
$CArr["$tmp[1]"] = $tmp[2];
}
}
Re: Simple PHP script - VMS problem [message #175822 is a reply to message #175820] Thu, 27 October 2011 17:10 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Pygmalion wrote:
> I just figure out that it might just as well be a read problem (reads
> only first line or reads all lines as one):
>
> while ($Line = fgets($fp, 999))
> {
> // split lines into identifier/counter
> if (ereg("([^ ]*) = *([0-9]*)", $Line, $tmp))
> {
> $CArr["$tmp[1]"] = $tmp[2];
> }
> }

be aware that VMS text files are ...'interesting' with respect to
end-of-line characters.

http://www.process.com/techsupport/multinet/794/10.html

This may be an issue..you need to dig deeper.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: My first PHP Script...
Next Topic: ZIP file download
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 18:29:17 GMT 2024

Total time taken to generate the page: 0.08022 seconds