Page 1 of 1

Broken script..

Posted: Mon Feb 21, 2005 6:09 pm
by nielsene
One of my scripts just broke, under slightly unusual circumstances, and I was wondering if anyone here has any ideas about what might have happened.

1. The circumstances: This script is part of a cron job that runs every minute. The script checks if a modified flag is more recent than the cached pages and if it is it rebuilds a whole bunch of other pages. (it also checks that another rebuild isn't in progress, etc)

The hosting company was doing some upgrades and at some point thereafter I started receiving automated cron failures:
'/usr/libexec/ld-elf.so.1: /usr/local/lib/libxml2.so.5: Undefined symbol
"pthread_once"'
even with cron message /dev/null'd. I spoke to the hosting company, they changed something and now it segfaults when run by cron, and runs, but incorrectly when run from the command-line.

The script previously has been in operations for about 3 years, with no problems. I think the hosting company is a little stumped, so I'm hoping to find something to help them out.

2. What I've discovered: Inside some of the code, its handling of arrays seems very wrong now. Condensing it to its simplest:

Code: Select all

$aStyle = array(1,2,3);
print_r($aStyle);
foreach ($aStyle as $anEvent) {
  print_r($anEvent);
}
Yields

Code: Select all

Array
(
    ї0] => 1
    ї1] => 2
    ї2] => 3
)
Array
(
    ї0]=>1
    ї1]=>0
)
Array
(
    ї0]=>2
    ї1]=>0
)
Array
(
    ї0]=>3
    ї1]=>0
)
Does anyone have any clue why its turning the scalars into an array and where the '0' elements are coming from?

Thank you

Posted: Mon Feb 21, 2005 6:17 pm
by feyd
that specific code outputs your example output on the server?

Posted: Mon Feb 21, 2005 6:35 pm
by nielsene
Yes.

Code: Select all

nielsene# more testing-php.php
#!/usr/local/bin/php
<?php
$aStyle = array(1,2,3);
print_r($aStyle);
foreach ($aStyle as $anEvent) &#123;
  print_r($anEvent);
&#125;
?>
nielsene# ./testing-php.php 
Array
(
    &#1111;0] => 1
    &#1111;1] => 2
    &#1111;2] => 3
)
Array
(
    &#1111;0] => 1
    &#1111;1] => 0
)
Array
(
    &#1111;0] => 2
    &#1111;1] => 1
)
Array
(
    &#1111;0] => 3
    &#1111;1] => 2
)

Posted: Mon Feb 21, 2005 6:38 pm
by feyd
definitely sounds like the rebuild of php screwed it up big time.

Posted: Mon Feb 21, 2005 6:43 pm
by patrikG
looks very odd.

$anEvent wasn't populated before?

Have you tried initialising every variable before it's set?

Posted: Mon Feb 21, 2005 8:51 pm
by nielsene
OK, looks like its a commonly reported gotcha at bugs.php.net, but always labelled as "bogus", grrr...

Apparently the 4.3.9 -> 4.3.10 upgrade breaks the semantics of foreach (due to a PHP5 inspired optimization) in such a way that all the Zend add-ons crash and burn. Because its the Zend add-ons that PHP claims cause the problem, they won't accept responsibility for the breaks... hence the "bogus"...

I've forwarded the information and the test cases to my hoster, hopefully things get resolved soon. I don't know if this will fix the core-dumpings or not, but it seems likely if the Zend add-ons are mangling the internal structure as the PHP guys imply... (Of course I'm a little peeved at the finger pointing between PHP and Zend.... its not like they're not closely coupled....)

Thanks for confirming that something looked odd with my original test case.