I wrote a script to read the Netflix catalog and populate my DB. Everything worked fine as a web script (except for timeouts) so I shifted to calling directly from the console.
I noticed a few oddities, like __construct() no longer being called (but that was easily remedied using the class name as a function.
Now I can’t get my arrays to work as before, here’s the general idea.
(Actually I have tried a few combinations, so I’ll share them all)
1 – this worked in the web script version just fine, no longer works calling from console
//declare empty
var $genreArray=array();
//later I add values one at a time as the XML is parsed
array_push($this->genreArray,$attrs['term']);
//after I have parsed an entire "title" element, I iterate the array
foreach ($this->genreArray as $value) {
// never gets called - array seen as empty
$this->db->linkGenre($value,$this->title_uid);
}
2 – so I tried the PHP manual; recommendation – nothing
//declare empty
var $genreArray=array();
//later I add values one at a time as the XML is parsed
$this->genreArray[]=$attrs['term'];
//after I have parsed an entire "title" element, I iterate the array
foreach ($this->genreArray as $value) {
// never gets called - array seen as empty
$this->db->linkGenre($value,$this->title_uid);
}
3 – so finally I tried manually tracking the index
//declare empty array
var $genreArray=array();
var $gi=0;
//later I add values one at a time as the XML is parsed
$this->genreArray[$this->gi++]=$attrs['term'];
//after I have parsed an entire "title" element, I iterate the array
foreach ($this->genreArray as $value) {
// never gets called - array seen as empty
$this->db->linkGenre($value,$this->title_uid);
}
So I am totally stumped now.
Has anyone declared empty arrays and populated via console?
(All 3 of these work via the web – so I need a console expert here)
Thanks for the support, here are the additional details requested;
php -v
PHP 4.4.9 (cli) (built: Sep 17 2008 12:02:18)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies
with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies
Each snippet was tried in a separate run. What details about the class are you interested in?
I have used echo statements to verify that the code is being called as expected. And if I hit the script through a URL everything kicks off fine (for the first few thousand records until the timeout).
No errors are being thrown, I even tried adding…
error_reporting(E_ALL);
ini_set('display_errors', true);
It sounds like your command-line and web server PHP are different versions. Is your CLI PHP 4? The function
phpversion()will tell you the version in both CLI and web.Have you checked your error log? You didn’t mention it, but that would be the first place to look.