Odd Script Anomalies Between Two Servers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Odd Script Anomalies Between Two Servers

Post by nickvd »

I have a content editor that I wrote a LOOONG time ago and has since been re-written, however a client who is using it has encountered a problem I have yet to see anywhere else. They have been editting their classifieds page (a huge static html file), for over 2 years without problems, now all of a sudden it doesn't appear in the file-list in the application. The file size is fairly large, at 250kb.

I have done everything in my power to determine the cause of the problem, but I'm only coming up with memory limits, but the script execution is not halted, and error_reporting is coming up with nothing but a couple undefined indexes.

I have uploaded the exact script and files to a different host and everything works perfectly. I am at my wits end with this... If it was a simple out of memory problem, wouldn't the script die?

Server One (WORKS FINE HERE):

Code: Select all

PHP Version: 4.3.10
PHP OS: Linux
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Memory Limit: 18388608
Loaded Extensions:
   xslt             xml              wddx             tokenizer     
   standard         sockets          session          pspell        
   posix            pfpro            pcre             overload      
   odbc             mysql            mhash            mcrypt        
   mbstring         imap             gmp              gettext       
   gd               ftp              exif             dbase         
   dba              curl             ctype            calendar      
   bz2              bcmath           zlib             openssl       
   apache           cybercash        Zend Optimizer
Server TWO (Fails on files over approx 90kb):

Code: Select all

PHP Version: 5.2.1
PHP OS: Linux
Error Reporting: 6135 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: On
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Memory Limit: 128M
Loaded Extensions:
   xmlwriter    libxml       dom          xmlreader 
   xml          wddx         tokenizer    session   
   pcre         SimpleXML    SPL          PDO       
   soap         siteguard    SQLite       standard  
   Reflection   pdo_sqlite   mysql        mcrypt    
   json         imap         iconv        hash      
   gettext      gd           filter       dbase     
   dba          date         curl         ctype     
   zlib         openssl      apache

Relevant Code:

Code: Select all

function getBlocks($f) {
   $file = file_get_contents($f);
   $pat = "#<!--EDITOR:([a-zA-Z0-9\-_ ]*?),([a-zA-Z0-9\-_ ]*?),([a-zA-Z0-9\-_ ]*?)-->(.*?)<!--:EDITOR-->#is";

   //debug:   echo "File [Name: {$f}] [Size: ".filesize($f)."]: ".print_r(preg_match_all($pat,$file,$mat,PREG_SET_ORDER),1)."<br/>";
   
   if (preg_match_all($pat,$file,$mat,PREG_SET_ORDER)) {
      $x=0;
      foreach($mat as $v) {
         $ret[$x]['name'] = trim($v[1]);
         $ret[$x]['desc'] = trim($v[2]);
         $ret[$x]['type'] = trim($v[3]);
         $ret[$x++]['text'] = trim($v[4]);
      }
      return $ret;
   }
   return false;
}

function getAllBlocks($dir="./") {
   $d = dir($dir);
   $editBlocks = array();
   $fileExt = array("html","php");
   while (false !== ($entry = $d->read())) {
      if ($entry != end(explode("/",$_SERVER['PHP_SELF'])) && in_array(end(explode(".",$entry)),$fileExt)) {
         if ($temp = getBlocks($dir.$entry)) {$editBlocks[$entry] = $temp;}
      }
   }
   $d->close();
   return $editBlocks;
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe more debug output?

Code: Select all

function getBlocks($f) {
   $file = file_get_contents($f);
   $pat = "#<!--EDITOR:([a-zA-Z0-9\-_ ]*?),([a-zA-Z0-9\-_ ]*?),([a-zA-Z0-9\-_ ]*?)-->(.*?)<!--:EDITOR-->#is";

   echo "<div>Debug getBlocks($f): read ", strlen($f), "bytes</div>\n";
   if (preg_match_all($pat,$file,$mat,PREG_SET_ORDER)) {
      $x=0;
      foreach($mat as $v) {
      	echo "<div>Debug getBlocks($f): match ", join(' : ', $v),"</div>\n";
         $ret[$x]['name'] = trim($v[1]);
         $ret[$x]['desc'] = trim($v[2]);
         $ret[$x]['type'] = trim($v[3]);
         $ret[$x++]['text'] = trim($v[4]);
      }
      echo "<div>Debug getBlocks($f): return array</div>\n";
      return $ret;
   }
   echo "<div>Debug getBlocks($f): return false</div>\n";
   return false;
}
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Printing stuff within the loop would cause output too large to be read.

//debug: echo "File [Name: {$f}] [Size: ".filesize($f)."]: ".print_r(preg_match_all($pat,$file,$mat,PREG_SET_ORDER),1)."<br/>";

Is outputting the filename/filesize and whether it found a match or not. It's output is below:

WORKING SERVER

Code: Select all

Memory Usage Before: 99,376bytes
File [Name: ./big.html] [Size: 387863]: 1
File [Name: ./177k_dclassifieds.php] [Size: 177945]: 1
File [Name: ./info.php] [Size: 2296]: 0
File [Name: ./106k_classifieds.php] [Size: 106867]: 1
File [Name: ./101k_classifieds2.php] [Size: 101644]: 1
File [Name: ./classifieds.php] [Size: 255089]: 1
File [Name: ./60k_WORKING_classifieds.php] [Size: 60474]: 1
Memory Usage After: 1,194,016bytes

BROKEN SERVER

Code: Select all

Memory Usage Before: 135,288bytes
File [Name: ./info.php] [Size: 2362]: 0
File [Name: ./106k_classifieds.php] [Size: 106867]: 0
File [Name: ./classifieds.php] [Size: 255089]: 0
File [Name: ./big.html] [Size: 96992]: 1
File [Name: ./101k_classifieds2.php] [Size: 101644]: 0
File [Name: ./177k_dclassifieds.php] [Size: 177945]: 0
File [Name: ./60k_WORKING_classifieds.php] [Size: 60474]: 1
Memory Usage After: 297,416bytes
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Then at lest print the strlen($f) and count($ret)

Code: Select all

function getBlocks($f) {
   $file = file_get_contents($f);
   $pat = "#<!--EDITOR:([a-zA-Z0-9\-_ ]*?),([a-zA-Z0-9\-_ ]*?),([a-zA-Z0-9\-_ ]*?)-->(.*?)<!--:EDITOR-->#is";

   echo "<div>Debug getBlocks($f): read ", strlen($f), "bytes</div>\n";
   if (preg_match_all($pat,$file,$mat,PREG_SET_ORDER)) {
      $x=0;
      foreach($mat as $v) {
         $ret[$x]['name'] = trim($v[1]);
         $ret[$x]['desc'] = trim($v[2]);
         $ret[$x]['type'] = trim($v[3]);
         $ret[$x++]['text'] = trim($v[4]);
      }
      echo "<div>Debug getBlocks($f): ", count($ret)," matches</div>\n";
      echo "<div>Debug getBlocks($f): return array</div>\n";
      return $ret;
   }
   echo "<div>Debug getBlocks($f): return false</div>\n";
   return false;
}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The output seems to be showing the same files, hust different values for each file in the output. Can you ls the directories and compare what is returned from the filesystem to see if the server might be returning information differently than expected? It is a complete shot in the dark, but it might be something to try? Can you run a simple script to just scan the directory to see what's in it?
Post Reply