0

I was having some issues yesterday with this, but I already managed to solve it using only API calls, as I was using both API and Magento Core.

This is my actual code:

        $proxy = new SoapClient($this->_api_url); // TODO : change url
        $sessionId = $proxy->login($this->_user, $this->_password); // TODO : change login and pwd if necessary
        $pageURL= $this->_page_url;
        $result = $proxy->catalogProductList($sessionId);

        $product_list = array();

        foreach($result as $p)
        {
            $starttime = microtime(true);

            $id = $p->product_id;
            $info = new stdclass();
            $info->attributes = array('sku', 'name', 'description', 'price', 'url_path');
            $product = $proxy->catalogProductInfo($sessionId, $id, NULL, $info);
            $image = $proxy->catalogProductAttributeMediaList($sessionId, $id, NULL, 'ID');

            $endtime = microtime(true);
            $timediff = $endtime - $starttime;

            echo "api calls $timediff <br><br>";

            $name = $product->name;
            $description = $product->description;
            $price = $product->price;
            $formatted_price = number_format($price, 2);    
            $image_url = $image[0]->url;
            $product_url = $product->url_path;
            $product_url = $pageURL.$product_url;
            $sku = $product->sku;

            $my_product = new Product();
            $my_product->id = $id;
            $my_product->name = $name;
            $my_product->description = $description;
            $my_product->price = $formatted_price;
            $my_product->image_url = $image_url;
            $my_product->product_url = $product_url;
            $my_product->sku = $sku;
            $product_list[] = $my_product;
        }

        return $product_list;

The problem with this approach is, each product needs 2 API calls, one for name, description, sku, etc, and another one for the image url. This takes too long, as for 3 products that I have, it takes like 5 seconds to load the page (two api calls for each one is like 1.5s). Is this the normal behavior of Magento API, or there is a problem with my system? Will I need to change all my method?

BTW, I'm testing this in localhost.

1

0,5s - 1,5s is a pretty standard response time from the SOAP API, also on localhost.

I created a small SOAP performance test-script some time ago which does nothing more than 10x10 login and endSession requests via SOAP API v1. No specific action was performed. 1 request took between 0,9 and 1,4 seconds with my local webserver.

SOAP is a well defined web-service which has pre-built standards (SOAPv1, SOAPv2, SOAPv2 WS-I) that uses XML for its requests and is heavyweight compared to REST. The speed is definitely a disadvantage of SOAP.

You might also consider enabling the WSDL-Cache and disabling automatic indexing to speed up SOAP imports. Check out this Blogpost (in German, google translate might help): Performance Tests with product import via SOAP (in German).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.