我有一个复杂的问题需要一些指导。我们是一家非营利组织,负责认证世界各地的工厂是否符合道德规范。我们有一个 WSDL Web 服务,它返回全球各国认证工厂的名称和联系信息。它接受三个字母的字符串作为参数(即BGD
孟加拉国、CHN
中国、COL
哥伦比亚)。
我设计了一个带有 HTML 选择的页面,以便用户可以选择一个国家并查看工厂列表。我希望能够编写某种过滤器,仅将具有认证工厂的国家/地区放在此列表中,而将那些没有的国家排除在外。
我已经编写了以下代码来完成这项工作,但是它非常缓慢并且确实使网站陷入困境。(为简洁起见,我只包括了前几个国家。整个数组包括大约 210 个国家。此外,该factCountByCountryID()
函数返回给定国家当前的工厂数量。
<?php
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient("http://apollov-dev.worlddata.com:8080/WrapSystem/services/FactoriesWS?wsdl",array("trace" => 1, "exceptions" => 0));
$countryList=array("AFG"=>"Afghanistan","ALA"=>"Aland Islands","ALB"=>"Albania","DZA"=>"Algeria","ASM"=>"American Samoa","AND"=>"Andorra","AGO"=>"Angola","AIA"=>"Anguilla","ATG"=>"Antigua and Barbuda","ARG"=>"Argentina","ARM"=>"Armenia","ABW"=>"Aruba","AUS"=>"Australia","AUT"=>"Austria","AZE"=>"Azerbaijan","BHS"=>"Bahamas","BHR"=>"Bahrain","BGD"=>"Bangladesh","BRB"=>"Barbados","BLR"=>"Belarus","BEL"=>"Belgium","BLZ"=>"Belize","BEN"=>"Benin","BMU"=>"Bermuda","BTN"=>"Bhutan","BOL"=>"Bolivia","BIH"=>"Bosnia and Herzegovina","BWA"=>"Botswana","BRA"=>"Brazil","VGB"=>"British Virgin Islands","BRN"=>"Brunei Darussalam","BGR"=>"Bulgaria","BFA"=>"Burkina Faso","BDI"=>"Burundi","KHM"=>"Cambodia","CMR"=>"Cameroon","CAN"=>"Canada","CPV"=>"Cape Verde","CYM"=>"Cayman Islands");
foreach($countryList as $code=>$country)
{
$params->countryCd=$code;
$number=$client->factCountByCountryID($params);
$factval=$number->factCountByCountryIDReturn;
if($factval!=0)
{
$countriesWithFactories["$code"]="$country";
}
else continue;
}
?>