Hi, I need some help with some Python code - please. What am I doing wrong with the Python code? How can I make the Python code work faster? Many thanks for any help. ---------------------------------------------------------------- PYTHON import time from pysimplesoap.client import SoapClient def checkDomain(vars): start = time.clock() client = SoapClient(wsdl="https://api.xxxxxxx.com.au/?wsdl") data = {'resellerID': vars['resellerID'], 'domainName': vars['domainName'], 'apiKey': vars['apiKey']} output=client.checkDomain(data) #print "available : %s " % output['return']['available'] print "status : %s " % output['return']['status'] end = time.clock() print "time : %f " % (end - start) vars = { 'resellerID': 'xxxxxxx', 'domainName': 'xxxxxxx.com', 'apiKey': 'xxxxxxx' } checkDomain(vars) Code (markup): PYTHON RESSULT status : AVAILABLE time : 9.981930 Process finished with exit code 0 Python results time is usually from 4.5 - 10 seconds ---------------------------------------------------------------- PHP <?php $start = microtime(TRUE); echo domainAvailable($domainName="xxxxxxx.com")."<br />\n"; $finish = microtime(TRUE); echo "time : ".($finish - $start); function domainAvailable($domainName){ $api_id = 'xxxxxxx'; $api_key = 'xxxxxxx'; try { // New soap connection $client = new SoapClient(null, array('location' => 'https://api.xxxxxxx.com.au/?wsdl','uri' => "")); // Data array $data = array('resellerID' => $api_id, 'apiKey' => $api_key, 'domainName' => $domainName); // Attempt the update with the API $output = $client->checkDomain($data); $output->status=trim($output->status); if ($output->status == "AVAILABLE") { return $output->status; }elseif($output->status == "UNAVAILABLE") { return $output->status; }else{ return 'Domain Status is unknown: ' . $output->status; } } catch (SoapFault $fault) { print_r($fault); } } ?> Code (markup): PHP RESULT AVAILABLE time : 1.0080101490021 PHP results time is usually from 1.0 - 2.5 seconds Many thanks for your time/ideas - cheers
Hi - thanks for your time. It is the latest/fresh install of Python 2 running on a Win 7 machine - many thanks
Try adding this: import logging logging.basicConfig(level=logging.DEBUG) logging.getLogger('pysimplesoap.client').setLevel(logging.DEBUG) Code (python): And add trace=True parameter to the soapclient constructor need to see what's going on
It's hard to see the bottleneck in big wsdls. I would try it out with SUDs instead. I don't think it's a problem with your code but with the SOAP client and the fact that php is faster than python by default. Check this post for some optimizations if you can apply them: http://stackoverflow.com/questions/7739613/python-soap-client-use-suds-or-something-else/7852994#7852994
If I may ask - why is it important to get it running faster in Python? It's already working in PHP, why not just use that?
Thanks so much PDD - I will check it out - thanks for all your help. @PoPSiCLe thanks - I was hoping to use multithreading and PHP can't do multithreading - so I thought I would move it over to Python - cheers