Domanda

I have this feed with 10,000 records and a loop to obtain all that products and then create a product array using those columns.

That map is created differently for each retailer, so product name can be the name of the product or it can be two columns of the feed. Below is an example.

The problem i am facing is that each loop after do eval, eval, eval... it starts increasing madly the time. Even when there are no functions at all.

Eval is creating references ? functions ? temp vars ? its there a way to reset all of that ?

DEBUG TIME

[2014-05-14 10:21:08][DEBUG] Converted 500 products in 0.48338389396667 Memory usage: 247750752 Read / Total: 500 / 108640

(...)

[2014-05-14 10:26:06][DEBUG] Converted 500 products in 6.9182150363922 Memory usage: 247751288 Read / Total: 50000 / 108640

(...)

[2014-05-14 10:28:03][DEBUG] Converted 500 products in 7.5416939258575 Memory usage: 247749704 Read / Total: 60000 / 108640

EXAMPLE

For the Merchant A i am getting the product name with this php function:

array_explode(",",str_replace(" ","",$NAME))[0];

So my mapping $v will have a index "f" with the follow value:

array_explode(",",str_replace(" ","",$NAME))[0];

After i do the eval of that map

foreach($map as $k=>$v) {
    (...)
    $value = eval('return ' . $v["f"] . ";");
    (...)
}

This works just fine i get all my product array just fine, but this is increasing maddly the execution time of my script. If i take that away the script runs fines with a 0.4secs per 500 lines / products.

I need the eval as i am using php code to parse / style the feed.

Help ? :)

È stato utile?

Soluzione

foreach($map as $k=>$v) {
    (...)
    $value = eval('return ' . $v["f"] . ";");
    (...)
}

You cannot return from a foreach. You can but that would assume 1. you are inside a function or method and 2. only the first result would be returned, because after return it breaks the loop.

If I get this wrong, it doesnt make sense either, why don't you:

$value = $v["f"];

Update:

When, according to your comment, $v["f"] is a function, use call_user_func instead of eval:

$value = call_user_func($v["f"]);

Altri suggerimenti

Even ashamed to say that ... WAS MY FAULT!! No problem with it i was just running it with the -d xdebug.remote.autostart=1 and each eval was opening a xdebug thing.

Sorry :( thanks for your help guys!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top