Broken script..

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
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Broken script..

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that specific code outputs your example output on the server?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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
)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

definitely sounds like the rebuild of php screwed it up big time.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

looks very odd.

$anEvent wasn't populated before?

Have you tried initialising every variable before it's set?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
Post Reply