Errors on DH Server and NOT on Other Web Host Svr

design

#1

Hi,

Thanks for Reading and for Helping Me keep My Sanity!

I’ve transferred pages from a different web host to DreamHost and have set Up My Scripts properly,
yet, I’m getting errors where there should Not Be…
(FYI: I’m NOT a newbie…)
:slight_smile:

Here’s one of the issues:
I’m getting an error when attempting to load a script for My RSS Feed on the main page.
Here is the line:

There is NO ISSUE on the OTHER Webhost with this script, by the way.

(I’ll copy the scripts below.)

Near the top of the page,
one of the first lines of code is as follows:

When I comment out the following line:

and make it just the error stops...

I’ve set this up EXACTLY how it’s set up on the other Web Host’s Server,
including CHMODing to 755 (I know that DH uses SuExec Exclusively, so I cannot use 777)

Besides that, there is NO DIFFERENCE!

I can access the database with No Problems …
(the index.php page mentioned here, that is getting the errors, is mostly (mySQL) database generated…)

… anyway, the scripts are below.

Thank You Again for Your Help!

Christopher

PS. The Error messages are generated on IE ONLY,
however,
the RSS Feed will not work on Opera, Firefox, or IE.
ON the DH Server, that is…
It ALL Works on a different webhosts Server…
(Not slamming DH, just explaining the issue…)

================================
firstborn.php

<?php # The cache folder should be writable define('CACHE_DIR', dirname(__FILE__).'/cache/'); # Cache expires after 60 minutes. define('CACHE_LIMIT', 60); # Script url define('SCRIPT_URL', $_SERVER['PHP_SELF']); # We have different feeds $feeds = array(); $feeds[] = 'http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&language=en-US&output=RSS20&fsop=1&fsoo=1&sass=gomarket1&frpp=25'; if(isset($_GET['js']) && $_GET['js']) { # Lets get all feed items $items = getFromFeeds($feeds, CACHE_LIMIT); header('Content-type:text/plain'); ?>

var rssTickElem = null;
var rssTickIndex = -1;
if(typeof rssTick == ‘undefined’) {
var rssItems = new Array();
var rssDate = “”;
function rssTick(elemID, interval) {
if(!document.getElementById) return;
if(!document.getElementById(elemID)) return;
rssTickElem = document.getElementById(elemID);
if(interval > 0) setInterval(‘rssTickChange()’,interval*1000);
rssTickChange();
}
function rssTickChange(step) {
// When no items are available, do nothing
if(rssItems.length < 1) return;

if(!step) step = 1;

rssTickIndex += step;
if(rssTickIndex < 0) rssTickIndex = rssItems.length - 1;
if(rssTickIndex >= rssItems.length) rssTickIndex = 0;
// Get next item
rssTickElem.innerHTML = rssItems[rssTickIndex].site + ’ Click the Link Here --> ’ + rssItems[rssTickIndex].title + ‘’;
}
}
rssItems = new Array();

<?php foreach($items as $item) { echo "\n".'rssItems.push({title:"'.addSlashes(htmlspecialchars($item['title'])).'"'; echo ',link:"'.addSlashes(htmlspecialchars($item['link'])).'"'; echo ',site:"'.addSlashes(htmlspecialchars($item['site'])).'"'; echo '})'; } } else { # Example code echo ''; echo ''; echo ''; echo ''; echo '
<< >>'; echo ''; } # Library: functions and 3rd party opensource functions. function getFromFeeds($feeds, $cacheTimeOut=60) { $mainCache = CACHE_DIR.'/main.cache.php'; # Chech the main cache file if(is_file($mainCache) && filemtime($mainCache) > strtotime('-'.$cacheTimeOut.' hours') && filemtime($mainCache) > filemtime(__FILE__)) { # Include the cache include $mainCache; # If items are found, return immediately if(is_array($items) && count($items) > 0) { return $items; } } $items = array(); foreach($feeds as $feed) { $feed_items = getCachedFeedItems($feed, $cacheTimeOut); $items = array_merge($items, $feed_items); } # Writeback to Cache $f = fopen($mainCache,'w'); if($f) { fwrite($f, '<'.'?php $items='.var_export($items,true).'; ?'.'>'); fclose($f); } return $items; } function getCachedFeedItems($url, $cacheTimeOut=60) { $cacheFile = CACHE_DIR.'/'.preg_replace('/\W/', '', $url).'.txt'; if(is_file($cacheFile) && filemtime($cacheFile) > strtotime('-'.$cacheTimeOut.' hours') && filemtime($cacheFile) > filemtime(__FILE__)) { include $cacheFile; if(is_array($items) && count($items) > 0) { return $items; } } $items = getRSSFeed($url); # Writeback to Cache $f = fopen($cacheFile,'w'); if($f) { fwrite($f, '<'.'?php $items='.var_export($items,true).'; ?'.'>'); fclose($f); } return $items; } function getRSSFeed($url) { $items = array(); $f = file_get_contents($url); $data = xml_unserialize($f); if(!isset($data['rss']['channel']['item'][0])) return array(); foreach($data['rss']['channel']['item'] as $item) { $items[] = array('link' => $item['link'], 'title' => $item['title'], 'date' => isset($item['pubDate']) ? $item['pubDate'] : '', 'site' => $data['rss']['channel']['title'], ); } return $items; } ?> <?php ################################################################################### # # XML Library, by Keith Devens, version 1.2b # http://keithdevens.com/software/phpxml # # This code is Open Source, released under terms similar to the Artistic License. # Read the license at http://keithdevens.com/software/license # ################################################################################### ################################################################################### # XML_unserialize: takes raw XML as a parameter (a string) # and returns an equivalent PHP data structure ################################################################################### function & XML_unserialize(&$xml){ $xml_parser = &new XML(); $data = &$xml_parser->parse($xml); $xml_parser->destruct(); return $data; } ################################################################################### # XML_serialize: serializes any PHP data structure into XML # Takes one parameter: the data to serialize. Must be an array. ################################################################################### function & XML_serialize(&$data, $level = 0, $prior_key = NULL){ if($level == 0){ ob_start(); echo '<?xml version="1.0" ?>',"\n"; }

while(list($key, $value) = each($data))
if(!strpos($key, ’ attr’)) #if it’s not an attribute
#we don’t treat attributes by themselves, so for an empty element

that has attributes you still need to set the element to NULL

if(is_array($value) and array_key_exists(0, $value)){
XML_serialize($value, $level, $key);
}else{
$tag = $prior_key ? $prior_key : $key;
echo str_repeat("\t", $level),’<’,$tag;
if(array_key_exists("$key attr", $data)){ #if there’s an attribute for this element
while(list($attr_name, $attr_value) = each($data["$key attr"]))
echo ’ ‘,$attr_name,’="’,htmlspecialchars($attr_value),’"’;
reset($data["$key attr"]);
}

if(is_null($value)) echo " />\n";
elseif(!is_array($value)) echo ‘>’,htmlspecialchars($value),"</$tag>\n";
else echo “>\n”,XML_serialize($value, $level+1),str_repeat("\t", $level),"</$tag>\n";
}
reset($data);
if($level == 0){ $str = &ob_get_contents(); ob_end_clean(); return $str; }
}
###################################################################################

XML class: utility class to be used with PHP’s XML handling functions

###################################################################################
class XML{
var $parser; #a reference to the XML parser
var $document; #the entire XML structure built up so far
var $parent; #a pointer to the current parent - the parent will be an array
var $stack; #a stack of the most recent parent at each nesting level
var $last_opened_tag; #keeps track of the last tag opened.

function XML(){
$this->parser = &xml_parser_create();
xml_parser_set_option(&$this->parser, XML_OPTION_CASE_FOLDING, false);
xml_set_object(&$this->parser, &$this);
xml_set_element_handler(&$this->parser, ‘open’,‘close’);
xml_set_character_data_handler(&$this->parser, ‘data’);
}
function destruct(){ xml_parser_free(&$this->parser); }
function & parse(&$data){
$this->document = array();
$this->stack = array();
$this->parent = &$this->document;
return xml_parse(&$this->parser, &$data, true) ? $this->document : NULL;
}
function open(&$parser, $tag, $attributes){
$this->data = ‘’; #stores temporary cdata
$this->last_opened_tag = $tag;
if(is_array($this->parent) and array_key_exists($tag,$this->parent)){ #if you’ve seen this tag before
if(is_array($this->parent[$tag]) and array_key_exists(0,$this->parent[$tag])){ #if the keys are numeric
#this is the third or later instance of $tag we’ve come across
$key = count_numeric_items($this->parent[$tag]);
}else{
#this is the second instance of $tag that we’ve seen. shift around
if(array_key_exists("$tag attr",$this->parent)){
$arr = array(‘0 attr’=>&$this->parent["$tag attr"], &$this->parent[$tag]);
unset($this->parent["$tag attr"]);
}else{
$arr = array(&$this->parent[$tag]);
}
$this->parent[$tag] = &$arr;
$key = 1;
}
$this->parent = &$this->parent[$tag];
}else{
$key = $tag;
}
if($attributes) $this->parent["$key attr"] = $attributes;
$this->parent = &$this->parent[$key];
$this->stack[] = &$this->parent;
}
function data(&$parser, $data){
if($this->last_opened_tag != NULL) #you don’t need to store whitespace in between tags
$this->data .= $data;
}
function close(&$parser, $tag){
if($this->last_opened_tag == $tag){
$this->parent = $this->data;
$this->last_opened_tag = NULL;
}
array_pop($this->stack);
if($this->stack) $this->parent = &$this->stack[count($this->stack)-1];
}
}
function count_numeric_items(&$array){
return is_array($array) ? count(array_filter(array_keys($array), ‘is_numeric’)) : 0;
}

?>

================================
main.cache.php

<?php $items=array (); ?>

// Actually, this file has the contents from the rss feed on ebay, of which, is correct…)


#2

function getRSSFeed($url) { $items = array(); $f = file_get_contents($url); $data = xml_unserialize($f); if(!isset($data['rss']['channel']['item'][0])) return array(); foreach($data['rss']['channel']['item'] as $item) { $items[] = array('link' => $item['link'], 'title' => $item['title'], 'date' => isset($item['pubDate']) ? $item['pubDate'] : '', 'site' => $data['rss']['channel']['title'], ); } return $items; }You will need to patch the function above to use cURL because DreamHost has disabled the PHP option allow_url_fopen.

I’m glad you posted code … but when getting error messages please post the error messages too.

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#3

Hi Atropos7,

Thanks for Helping!

k… The curl comment explains a different issue I’m having with a different DH Account, thanks!

The Errors are pasted below.
(using the Default MS Debugger)

Any Ideas what’s wrong?

I also have a screen shot of the error message,
but it only says that a run-time error has occurred.

That’s why I copied and pasted the Debug Code below.

Thanks.

Christopher



Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_parser_set_option(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 194

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 195

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 195

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_element_handler(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 196

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_character_data_handler(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 197

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_parser_free(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 199

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_parse(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 204

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_parse(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. in user/firstborn.php on line 204

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in user/firstborn.php on line 116

Warning: file_get_contents(http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&language=en-US&output=RSS20&fsop=1&fsoo=1&sass=gomarket1&frpp=25) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in user/firstborn.php on line 116
var rssTickElem = null; var rssTickIndex = -1; if(typeof rssTick == 'undefined') { var rssItems = new Array(); var rssDate = ""; function rssTick(elemID, interval) { if(!document.getElementById) return; if(!document.getElementById(elemID)) return; rssTickElem = document.getElementById(elemID); if(interval > 0) setInterval('rssTickChange()',interval*1000); rssTickChange(); } function rssTickChange(step) { // When no items are available, do nothing if(rssItems.length < 1) return;

if(!step) step = 1;

rssTickIndex += step;
if(rssTickIndex < 0) rssTickIndex = rssItems.length - 1;
if(rssTickIndex >= rssItems.length) rssTickIndex = 0;
// Get next item
rssTickElem.innerHTML = rssItems[rssTickIndex].site + ’ Click the Link Here --> ’ + rssItems[rssTickIndex].title + ‘’;
}
}
rssItems = new Array();


#4

Thanks for Helping…

k… I’ve fixed and eliminated some of the errors,
but now, It’s almost fixed.

Remaining Errors are below.

Any Ideas on how to fix the rest?

Thanks.

Christopher



Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /user/firstborn.php on line 116

Warning: file_get_contents(http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&language=en-US&output=RSS20&fsop=1&fsoo=1&sass=gomarket1&frpp=25) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /user/firstborn.php on line 116
var rssTickElem = null; var rssTickIndex = -1; if(typeof rssTick == 'undefined') { var rssItems = new Array(); var rssDate = ""; function rssTick(elemID, interval) { if(!document.getElementById) return; if(!document.getElementById(elemID)) return; rssTickElem = document.getElementById(elemID); if(interval > 0) setInterval('rssTickChange()',interval*1000); rssTickChange(); } function rssTickChange(step) { // When no items are available, do nothing if(rssItems.length < 1) return;

if(!step) step = 1;

rssTickIndex = step;
if(rssTickIndex < 0) rssTickIndex = rssItems.length - 1;
if(rssTickIndex >= rssItems.length) rssTickIndex = 0;
// Get next item
rssTickElem.innerHTML = rssItems[rssTickIndex].site ’ Click the Link Here --> ’ rssItems[rssTickIndex].title ‘’;
}
}
rssItems = new Array();


#5

[quote]

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /user/firstborn.php on line 116



Warning: file_get_contents(url) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /user/firstborn.php on line 116
[/quote]
Again you need to use CURL instead of calling file_get_contents

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#6

Hi Atropos7,

Thanks for staying patient with My Q’s.

One last thing.

I finally eliminated the errors,
however,
the RSS FEED Is NOT Displaying like it’s SUPPOSED To.
There are Absolutely ZERO items displayed!
Yikes!!!

I’ve included the code below.

On the other Host, I didn’t have to modify the code at all,
so, therefore, it works like a Dream…

Why isn’t it working at all on DH?!?

Thanks for Your persistent help.

Christopher

======================
function getRSSFeed($url) {
$items = array();
$f = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($f, CURLOPT_URL, $url);
curl_setopt ($f, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($f, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($f);
curl_close($f);

$data = xml_unserialize($f);
if(!isset($data[‘rss’][‘channel’][‘item’][0])) return array();
foreach($data[‘rss’][‘channel’][‘item’] as $item) {
$items[] = array(‘link’ => $item[‘link’],
‘title’ => $item[‘title’],
‘date’ => isset($item[‘pubDate’])
? $item[‘pubDate’]
: ‘’,
‘site’ => $data[‘rss’][‘channel’][‘title’],
);
}
return $items;
}

======================


#7

$data = xml_unserialize($f);Uh… $f is not the string containing the XML data.

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#8

Hi Atropos7,

Thanks for commenting.

Actually, the Original Script (that is working elsewhere,)
here is the code:
$f = file_get_contents($url);
$data = xml_unserialize($f);

I had to change the file_get_contents($url) code,
but the $data line SHOULD stay the same.

Am I missing something?

Thanks.

Christopher


#9

curl_init returns a handle.
curl_exec returns the content.

You need to pass the content to xml_unserialize, not the handle.

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#10

Hi Atropos7,

Thanks for sticking with Me here.

k… I am now officially TOTALLY LOST!

What code SHOULD I be using instead of what I have, then?

I’m confused 'cause the ORIGINAL Script has the same $f passed to xml_unserialize…

Christopher


#11

Hi Atropos7,

k… I tried this to no avail:

function getRSSFeed($url) {
$items = array();
$f = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($f, CURLOPT_URL, $url);
curl_setopt ($f, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($f, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($f);
curl_close($f);

// $data = xml_unserialize($f);
$data = xml_unserialize($file_contents);
if(!isset($data[‘rss’][‘channel’][‘item’][0])) return array();
foreach($data[‘rss’][‘channel’][‘item’] as $item) {
$items[] = array(‘link’ => $item[‘link’],
‘title’ => $item[‘title’],
‘date’ => isset($item[‘pubDate’])
? $item[‘pubDate’]
: ‘’,
‘site’ => $data[‘rss’][‘channel’][‘title’],
);
}
return $items;
}
STILL not getting the content…

What am I missing?

Thanks.

Christopher