By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,777 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

variable getting cleared on host, works fine locally

100+
P: 110
I've got a php page which is outputing xml to a file.

The code has been working without a hitch for weeks when running as localhost, but a few days ago I uploaded it to my ec2 instance, and it doesn't seem to work.

the data is stored in $xml_output, and I've added the "echo xml_output" at the bottom of the page to see what the page is holding.

I can see that both servers are accessing the correct data from the
echo $name, $genre, etc. that I have put throughout the page.

On local host, echo $xml_output spits out the full page stream. on ec2, that is empty, even though the other variables along the way have not been.

File opens fine, sql connection isn't the issue, it seems that the xml_output is either being cleared or never adding the elements. VERY STRANGE

anybody seen this issue before with variable values not working? or disappearing?

Here is a subsection of the code.
Expand|Select|Wrap|Line Numbers
  1. $fh = fopen($m3xmlFile, 'w') or die("can't open file");
  2.  
  3. $xml_output = "";
  4. $xml_output .= "<cache>\n";
  5.  
  6.      while (list($key, $value) = each($y)) {
  7.       //Output the array key/value
  8.     $genreName = htmlentities($key, ENT_NOQUOTES);
  9. $xml_output .= "\t<genre>\n";
  10. $xml_output .= "\t\t<id>$value</id>\n";
  11. $xml_output .= "\t\t<name>$genreName</name>\n";
  12. $xml_output .= "\t</genre>\n";
  13.    }
  14.  
  15.  
  16. while($rowa = mysql_fetch_array($resulta, MYSQL_ASSOC))
  17. {
  18.  
  19. $name = htmlentities($rowa['name'], ENT_NOQUOTES);
  20. $specialCharReplace = array("&acute;", "&sect;", "&plusmn;", "", "&laquo;", "", "", "&cedil;", "&circ;", "&ring;", "", ",,", "", "&acirc;", "", "", "", "", "&tilde;", "&uml;", "&heart;", "&cent;", "&sup2;", "&cedil;", "&para;", "&copy;", "&trade;", "&not;", "&middot;", "&frac34;", "&macr;", "&iexcl;", "&curren;", "&sup3;", "&yen;");
  21. $name = str_ireplace($specialCharReplace, "", $name);
  22. $name = str_replace("", "", $name);
  23. $name = str_replace ("&Atilde;", "A", $name);
  24.  
  25. $xml_output .= "\t<artist>\n";
  26. $xml_output .= "\t\t<id>". $rowa['bid'] . "</id>\n"; 
  27.  $xml_output .= "\t\t<name>". $name . "</name>\n";
  28.     echo $name.'<br />';
  29. // do genre math
  30.  
  31. $genre = str_replace("/", "|", $rowa['genre']);
  32. echo $genre.'<br />';
  33. $gSplit = array();
  34. $gSplit = explode("|", $genre);
  35. $gSplit = array_unique($gSplit);
  36. print_r (array_unique($gSplit));
  37. $numarray = array();
  38.     foreach($gSplit as $gString) {
  39.  $genrenum = @$y[trim($gString)];
  40.     echo $genrenum.'<br />';
  41.  
  42.         array_push($numarray, $genrenum);
  43.     $numarray = array_unique($numarray);
  44.     $genreTotal = array_sum($numarray);
  45.  
  46. echo $genreTotal.'<br />';
  47. }
  48.  $xml_output .= "\t\t<genre>". $genreTotal ."</genre>\n";
  49.  
  50.    $xml_output .= "\t</artist>\n";
  51. }
  52. while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  53. {
  54.  
  55.     $xml_output .= "\t<song>\n";
  56.     $xml_output .= "\t\t<id>". $row['sid'] . "</id>\n"; 
  57.     $xml_output .= "\t\t<data>". $row['mipid'] . "</data>\n"; 
  58.     $xml_output .= "\t\t<artist>". $row['bid'] . "</artist>\n"; 
  59.     $xml_output .= "\t\t<popularity>".$row['plays']."</popularity>\n";
  60. //    if ($row['genrenum'] != "0"){
  61. // $xml_output .= "\t\t<genre>". $row['genrenum'] ."</genre>\n";
  62. //    } else {
  63. //    $xml_output .= "\t\t<genre></genre>\n";
  64.  // }
  65.    $xml_output .= "\t</song>\n";
  66. }
  67.  
  68. $xml_output .= "</cache>";
  69.  
  70. echo $xml_output;
  71.  
  72. fwrite($fh, $xml_output);
  73. fclose($fh);
  74.  
  75.  
Nov 5 '07 #1
Share this Question
Share on Google+
2 Replies


ak1dnar
Expert 100+
P: 1,584
What is the operating system on your hosting server? is it same as your local server OS? I think this problem is occurs because of the line breaks. waiting for your response.
Nov 6 '07 #2

100+
P: 110
The host is linux and my os is windows,
but this ended up being a configuration limiting the available file size that php can create on the host.

I added
Expand|Select|Wrap|Line Numbers
  1.  
  2. ini_set("memory_limit","100M");
  3.  
to the top of the page to get over the memory limit.

Hope fully somebody can find this useful in the future.
Nov 12 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.