Magento Forum

   
Custom PHP product import, looping problem
 
cshontz
Sr. Member
 
Avatar
Total Posts:  91
Joined:  2007-11-07
 

I’m writing a custom import to move product and images from our old site, to our new Magento site. It works well, except for one problem. After around (not consistent) 40 iterations, the script resets completely. Like an infinite loop, but the PHP file is re-executed completely.

The offending line of code is where it reads the JPG product image from the old site, and copies it to the new site. It does this successfully for around 40 iterations, but then re-executes the PHP file. Any thoughts?

file_put_contents($dest, file_get_contents($row[’image01’]));

$sql "SELECT * FROM cs_migrate LIMIT 50";

$result mysql_query($sql);

while(
$row mysql_fetch_array($result)) {

    $t 
time();

    
$count++;
        
    
$dest "migrate/" $t "_" $count ".jpg";
    
    
file_put_contents($destfile_get_contents($row['image01']));
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  91
Joined:  2007-11-07
 

I’ve tried different variations of this, increasing the memory limit, and so on… and it still works intermittently. Images are uploaded/copied successfully for only so many iterations, then the script starts over again completely - not just the loop. I’m not sure whats triggering this “start over”.

Maybe I need to put in a delay after every file_get_contents. I’ll try that.

Please… for the love of god… - what is causing this? :(

Update 1: Okay, its time-based, because setting a 5 second sleep at the end of each iteration reduces the number of files I’m able to upload before the PHP starts over. Something must be causing some sort of a timeout… I think.

Update 2: I omitted all superfluous code, and tried executing the PHP with just the bare necessities - just to see if it was something else conflicting with my file copy loop, and I was able to copy 160 files before the PHP “started over”. Better from 40, but the point is - it still does it. Basically, I can tell because $count keeps going back to 0.

I love spending 3 days on one simple problem like this - makes me love being a web developer!

Update 3: It loops, file_get_contents, apparently for no longer than 69 seconds.

Why can’t I have normal problems? You know… the kind that have solutions.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nabuhonodozor
Member
 
Avatar
Total Posts:  51
Joined:  2008-03-27
 

Hi,
It can be limit in executing scripts. I dont remember where but few months ago Ive played with php configuration and had also issues with breaking scripts - the solution was to lenghten script execution time but sorry , I dont remember what exactly I done to fix it.
best ,
Piotr

 
Magento Community Magento Community
Magento Community
Magento Community
 
cshontz
Sr. Member
 
Avatar
Total Posts:  91
Joined:  2007-11-07
 

Thanks, Piotr. smile

I’ve tried nearly everthing. The script starting anew on its own accord seems to be a very unique behavior. I haven’t been able to Google a solution or anything. I’m going to continue to scour the Internet for a solution shortly… but first, I’m going to go cry in bed.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top