Jump to content

Trying to get property of non-object in....


cgsmith105

Recommended Posts

Hello all you Gurus out there!

 

I hope to be contributing to this forum because I think I have some good information on PHP coding... you can be the judge in the end though :).  I need your help!

 

I am communicating to about 20 nodes that spit out XML data.  The nodes are parsed through and then displayed on a main page.  They are also parsed through and then pertinent data is inserted into a database.  I received the following error recently:

 

[15-Mar-2010 11:20:25] PHP Notice:  Trying to get property of non-object in /home/maverick/public_html/ramsey/insertintodb.php on line 71

 

I commented out the line but the script still runs forever.

 

Here is inserttodb.php:

<?php
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');
require "includes/include_load.php";
require_once "classes/class_maverick.php";
include "includes/config.php";
include "includes/opendb.php";
$mav01 = new Maverick();
$mav01->ipAddress = "http://75.73.35.73:81/sm101.xml";
$mav01->loadXml();

$mav04 = new Maverick();
$mav04->ipAddress = "http://75.73.35.73:84/sm101.xml";
$mav04->loadXml();

$mav05 = new Maverick();
$mav05->ipAddress = "http://75.73.35.73:85/sm101.xml";
$mav05->loadXml();

$mav06 = new Maverick();
$mav06->ipAddress = "http://75.73.35.73:86/sm101.xml";
$mav06->loadXml();

$mav08 = new Maverick();
$mav08->ipAddress = "http://75.73.35.73:88/sm101.xml";
$mav08->loadXml();

$mav09 = new Maverick();
$mav09->ipAddress = "http://75.73.35.73:89/sm101.xml";
$mav09->loadXml();

$mav10 = new Maverick();
$mav10->ipAddress = "http://75.73.35.73:90/sm101.xml";
$mav10->loadXml();

$mav11 = new Maverick();
$mav11->ipAddress = "http://75.73.35.73:91/sm101.xml";
$mav11->loadXml();

$mav17 = new Maverick();
$mav17->ipAddress = "http://75.73.35.73:97/sm101.xml";
$mav17->loadXml();

$mav18 = new Maverick();
$mav18->ipAddress = "http://75.73.35.73:98/sm101.xml";
$mav18->loadXml();

$mav20 = new Maverick();
$mav20->ipAddress = "http://75.73.35.73:100/sm101.xml";
$mav20->loadXml();

$btu01 = new Maverick();
$btu01->ipAddress = "http://75.73.35.73:112/sm101.xml";
$btu01->loadXml();

$btu04 = new Maverick();
$btu04->ipAddress = "http://75.73.35.73:114/sm101.xml";
$btu04->loadXml();

$btu07 = new Maverick();
$btu07->ipAddress = "http://75.73.35.73:118/sm101.xml";
$btu07->loadXml();

$btu10 = new Maverick();
$btu10->ipAddress = "http://75.73.35.73:120/sm101.xml";
$btu10->loadXml();

$outside = new Maverick();
$outside->ipAddress = "http://75.73.35.73:127/pc10180.xml";
$outside->loadXml();   // Line 70 -- I think the problem is happening here... not sure
$oahumd = $outside->validXml->Sensor[0]->SensorValue;  //line 71
$oatemp = $outside->validXml->Sensor[3]->SensorValue;

$node = "Hour";
$child = "PreviousHour";
$pM1 = $mav01->getNode($node, $child);
$pM4 = $mav04->getNode($node, $child);
$pM5 = $mav05->getNode($node, $child);
$pM6 = $mav06->getNode($node, $child);
$pM8 = $mav08->getNode($node, $child);
$pM9 = $mav09->getNode($node, $child);
$pM10 = $mav10->getNode($node, $child);
$pM11 = $mav11->getNode($node, $child);
$pM17 = $mav17->getNode($node, $child);
$pM18 = $mav18->getNode($node, $child);
$pM20 = $mav20->getNode($node, $child);
$pB1 = $btu01->getNode($node, $child);
$pB4 = $btu04->getNode($node, $child);
$pB7 = $btu07->getNode($node, $child);
$pB10 = $btu10->getNode($node, $child);


$pS1 = $pM4 - ($pM5 - $pM6);
$pS2 = $pM8 - ($pM9 - $pM10 - $pM11);
$JailHVAC_Prev = $pS1 + $pS2 + $pM17 + $pM18 + $pM20;
$JailGEN_Prev = $pM1 - $JailHVAC_Prev;
$JailTOTAL_Prev = $pM1;
$DetHeat_Prev = ($pB4 + $pB7 + $pB10)*1000; //Takes kBTU to mBTU

$JailSqFt = 150896;
$kWCost = 0.069;
$mWKBTU = 0.00000029307108333;
$mbtuCost = 82.39;
$decimals = 4;

$kw2BTU= 293; //1kw to mbtu

$CurrTOTAL_Prev = ($JailTOTAL_Prev / $kw2BTU) + $DetHeat_Prev;
//$CurrTOTAL2_Prev= number_format(($CurrTOTAL_Prev/$JailSqFt), $decimals);
$CurrTOTAL3_Prev = money_format("%.2n",($CurrTOTAL_Prev)*($mWKBTU * $mbtuCost));

//$JailGEN2_Prev= number_format(($JailGEN_Prev/$JailSqFt), $decimals);
$JailGEN3_Prev= money_format("%.4n",($JailGEN_Prev*$kWCost));

//$JailHVAC2_Prev = number_format(($JailHVAC_Prev/$JailSqFt), $decimals);
$JailHVAC3_Prev = money_format("%.4n",($JailHVAC_Prev*$kWCost));

//$JailTOTAL2_Prev=number_format(($JailTOTAL_Prev/$JailSqFt), $decimals);
$JailTOTAL3_Prev=money_format("%.4n",($JailTOTAL_Prev*$kWCost));

//$DetHeat2_Prev = number_format(($DetHeat_Prev/$JailSqFt), $decimals);
$DetHeat3_Prev = money_format("%.4n",($DetHeat_Prev*($mWKBTU * $mbtuCost)));

$date = date("Y-m-d");
$time = date("h:i:A");
$sql_ins = "";
$sql_ins.= "INSERT INTO detention (";
$sql_ins.= "datestamp,timestamp,totalenergy,totalcost,genenergy,gencost,hvacenergy,hvaccost,";
$sql_ins.= "detenergy,detcost,detheatenergy,detheatcost,oatemp,oahumid)";
$sql_ins.= "VALUES ('$date','$time','$CurrTOTAL_Prev','$CurrTOTAL3_Prev','$JailGEN_Prev','$JailGEN3_Prev','$JailHVAC_Prev','$JailHVAC3_Prev',";
$sql_ins.= "'$JailTOTAL_Prev','$JailTOTAL3_Prev','$DetHeat_Prev','$DetHeat3_Prev','$oatemp','$oahumd');";

mysql_query($sql_ins);

include "includes/closedb.php";
?>

 

Any ideas would be appreciated.  The script has been working for about 48 hours (runs every hour on cron) and then it just quit... stopped putting into the database.

 

 

Link to comment
Share on other sites

//$oahumd = $outside->validXml->Sensor[0]->SensorValue;
echo '<pre>' . print_r($outside->validXml->Sensor, true) . '</pre>';
exit;

 

//Edit

 

Replace that on line 71 and paste back the results...

Link to comment
Share on other sites

Hi Andy-H,

 

I tried the changes you said but unfortunately the server spit out a 500.  Here is the class "Maverick"... the function loadxml:

    public function loadXml() {  //loads xml and removes HTTP header from string
        $this->_contents = load($this->ipAddress);
        $this->_xmlDelete = substr($this->_contents, 0, (stripos($this->_contents, "<?")));
        $this->invalidXml = str_replace($this->_xmlDelete, '', $this->_contents);
        $this->validXml = simplexml_load_string($this->invalidXml);
    }

 

The load function is borrowed from http://www.bin-co.com/php/scripts/load/.

Link to comment
Share on other sites

Okay everyone.  I have narrowed it down and started testing the following:

<?php
include 'load.php';
$ipAddress = 'http://75.73.35.73:81/int2.csv';
$contents = load($ipAddress);
var_dump($contents);
exit;
?>

 

The above code produces False... but if you type in http://75.73.35.73:81/int2.csv you will receive a valid response.

 

However if you change the IP address to http://www.google.com you will see the contents are of Google. 

 

:wtf: :wtf:

 

Why is this!?  :shrug:

 

I tested it on two servers so far.  Load() works.  Not the IPs.

 

The weird thing is this: they were working fine prior to today.

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Maybe this seems like an obvious question, but why would you expect a set of routines that are designed to load an xml file to work ok on a file that contains comma separated values?

 

Putting that question aside... does the server utilize curl?  Notice [  if(function_exists("curl_init")  ] code in load(). 

 

 

 

 

Link to comment
Share on other sites

Gizmola,

 

I guess I do not understand exactly what functions are meant to load an XML file.  I use the load() script just to load any of the data needed for the application.  Not sure if there is a better/preferred way?  Once the address is loaded (ie Google) it puts the data into a string:

 

string(6514) 
"<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><title>Google</title><script>window.google={kEI:"mgSfS5W1L5jYerns5ZUM",kEXPI:"24029,24080",kCSI:{e:"24029,24080",ei:"mgSfS5W1L5jYerns5ZUM",expi:"24029,24080"},ml:function(){},kHL:"en",time:function(){return(new Date).getTime()},log:function(b,d,c){var a=new Image,e=google,g=e.lc,f=e.li;a.onerror=(a.onload=(a.onabort=function(){delete g[f]}));g[f]=a;c=c||"/gen_204?atyp=i&ct="+b+"&cad="+d+"&zx="+google.time();a.src=c;e.li=f+1},lc:[],li:0,Toolbelt:{}};
window.google.sn="webhp";window.google.timers={load:{t:{start:(new Date).getTime()}}};try{}catch(u){}window.google.jsrt_kill=1;
var _gjwl=location;function _gjuc(){var e=_gjwl.href.indexOf("#");if(e>=0){var a=_gjwl.href.substring(e);if(a.indexOf("&q=")>0||a.indexOf("#q=")>=0){a=a.substring(1);if(a.indexOf("#")==-1){for(var c=0;c<a.length;){var d=c;if(a.charAt(d)=="&")++d;var b=a.indexOf("&",d);if(b==-1)b=a.length;var f=a.substring(d,b);if(f.indexOf("fp=")==0){a=a.substring(0,c)+a.substring(b,a.length);b=c}else if(f=="cad=h")return 0;c=b}_gjwl.href="/search?"+a+"&cad=h";return 1}}}return 0}function _gjp(){!(window._gjwl.hash&&
window._gjuc())&&setTimeout(_gjp,500)};
window._gjp && _gjp()</script><style>td{line-height:.8em;}.gac_m td{line-height:17px;}form{margin-bottom:20px;}body,td,a,p,.h{font-family:arial,sans-serif}.h{color:#36c;font-size:20px}.q{color:#00c}.ts td{padding:0}.ts{border-collapse:collapse}em{font-weight:bold;font-style:normal}.lst{font:17px arial,sans-serif;margin-bottom:.2em;vertical-align:bottom;}input{font-family:inherit}.lsb,.gac_sb{font-size:15px;height:1.85em!important;margin:.2em;}#gbar{height:22px}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}#guser{padding-bottom:7px !important;text-align:right}#gbar,#guser{font-size:13px;padding-top:1px !important}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{color:#00c !important}</style><script>google.y={};google.x=function(e,g){google.y[e.id]=[e,g];return false};</script></head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b alink=#ff0000 onload="document.f.q.focus();if(document.images)new Image().src='/images/nav_logo7.png'" topmargin=3 marginheight=3><textarea id=csi style=display:none></textarea><iframe name=wgjf style=display:none></iframe><div id=ghead><div id=gbar><nobr><b class=gb1>Web</b> <a onclick=gbar.qs(this) href="http://images.google.com/imghp?hl=en&tab=wi" class=gb1>Images</a> <a onclick=gbar.qs(this) href="http://video.google.com/?hl=en&tab=wv" class=gb1>Videos</a> <a onclick=gbar.qs(this) href="http://maps.google.com/maps?hl=en&tab=wl" class=gb1>Maps</a> <a onclick=gbar.qs(this) href="http://news.google.com/nwshp?hl=en&tab=wn" class=gb1>News</a> <a onclick=gbar.qs(this) href="http://www.google.com/prdhp?hl=en&tab=wf" class=gb1>Shopping</a> <a href="http://mail.google.com/mail/?hl=en&tab=wm" class=gb1>Gmail</a> <a href="http://www.google.com/intl/en/options/" class=gb1 style="text-decoration:none"><u>more</u> »</a></nobr></div><div id=guser width=100%><nobr><a href="/url?sa=p&pref=ig&pval=3&q=http://www.google.com/ig%3Fhl%3Den%26source%3Diglk&usg=AFQjCNFA18XPfgb7dKnXfKz7x7g1GDH1tg" class=gb4>iGoogle</a> | <a href="/preferences?hl=en" class=gb4>Search settings</a> | <a href="https://www.google.com/accounts/Login?hl=en&continue=http://www.google.com/" class=gb4>Sign in</a></nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div></div> <center><br clear=all id=lgpd><img alt="Google" height=110 src="/intl/en_ALL/images/logo.gif" width=276 id=logo onload="window.lol&&lol()"><br><br><form action="/search" name=f><table cellpadding=0 cellspacing=0><tr valign=top><td width=25%> </td><td align=center nowrap><input name=hl type=hidden value=en><input name=source type=hidden value=hp><input type=hidden name=ie value="ISO-8859-1"><input autocomplete="off" maxlength=2048 name=q size=55 class=lst title="Google Search" value=""><br><input name=btnG type=submit value="Google Search" class=lsb><input name=btnI type=submit value="I&#39;m Feeling Lucky" class=lsb></td><td nowrap width=25% align=left><font size=-2>  <a href="/advanced_search?hl=en">Advanced Search</a><br>  <a href="/language_tools?hl=en">Language Tools</a></font></td></tr></table></form><br><span id=footer><center id=fctr><br><font size=-1><a href="/intl/en/ads/">Advertising Programs</a> - <a href="/services/">Business Solutions</a> - <a href="/intl/en/about.html">About Google</a></font><p><font size=-2>©2010 - <a href="/intl/en/privacy.html">Privacy</a></font></p></center></span> <div id=xjsd></div><div id=xjsi><script>if(google.y)google.y.first=[];if(google.y)google.y.first=[];google.dstr=[];google.rein=[];window.setTimeout(function(){var a=document.createElement("script");a.src="/extern_js/f/CgJlbhICdXMgACswCjhdQAgsKzAOOAwsKzAXOAYsKzAYOAUsKzAlOMqIASwrMCY4CSwrMCc4BCwrMDw4AiwrMEA4CywrMEQ4AiwrMEU4ASw/OamgJXCMX7I.js";(document.getElementById("xjsd")||document.body).appendChild(a);if(google.timers&&google.timers.load.t)google.timers.load.t.xjsls=(new Date).getTime();},0);
;google.neegg=1;google.y.first.push(function(){google.ac.m=1;google.ac.b=true;google.ac.i(document.f,document.f.q,'','','',{a:1,o:1});google.History&&google.History.initialize('/')});if(google.j&&google.j.en&&google.j.xi){window.setTimeout(google.j.xi,0);google.fade=null;}</script></div><script>(function(){
var b,d,e,f;function g(a,c){if(a.removeEventListener){a.removeEventListener("load",c,false);a.removeEventListener("error",c,false)}else{a.detachEvent("onload",c);a.detachEvent("onerror",c)}}function h(a){f=(new Date).getTime();++d;a=a||window.event;var c=a.target||a.srcElement;g(c,h)}var i=document.getElementsByTagName("img");b=i.length;d=0;for(var j=0,k;j<b;++j){k=i[j];g(k,h);if(k.complete||typeof k.src!="string"||!k.src)++d;else if(k.addEventListener){k.addEventListener("load",h,false);k.addEventListener("error",
h,false)}else{k.attachEvent("onload",h);k.attachEvent("onerror",h)}}e=b-d;function l(){google.timers.load.t.ol=(new Date).getTime();google.timers.load.t.iml=f;google.kCSI.imc=d;google.kCSI.imn=b;google.kCSI.imp=e;google.report&&google.report(google.timers.load,google.kCSI)}if(window.addEventListener)window.addEventListener("load",l,false);else if(window.attachEvent)window.attachEvent("onload",l);google.timers.load.t.prt=(f=(new Date).getTime());
})();

</script>"

 

curl is enabled on both servers.

 

 

Link to comment
Share on other sites

Hi again guys.

 

  I don't mean to be posting such fragmented finds.  It is appearing that the IP (http://75.73.35.73:81/) being used is what is causing the hang up (from what i can see).  For example: http://70.104.60.153/ works fine on a similar script.

 

  Any ideas on what to check?  The external ports are being forwarded to internal port 80s.  Like I said before... everything was working. (all the way up to about 12:00PM CST March 15th, 2010)

 

  I will be trying to install the script on a machine internal in the network to see what happens.  Its like someone flicked a dang light switch off, you know?

 

  Thanks in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.