使用中文搜索报错fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known

bug问题 · htony · 于 6年前 发布 · 3803 次阅读
1. in /www/web/fecshop/vendor/hightman/xunsearch/lib/XS.class.php at line 711
702703704705706707708709710711712713714715                    spl_autoload_register('XS::autoload', true, true);
 
/**
 * 修改默认的错误处理函数
 * 把发生的错误修改为抛出异常, 方便统一处理
 */
function xsErrorHandler($errno, $error, $file, $line)
{
    if (($errno & ini_get('error_reporting')) && !strncmp($file, XS_LIB_ROOT, strlen(XS_LIB_ROOT))) {
        throw new XSErrorException($errno, $error, $file, $line);
    }
    return false;
}
set_error_handler('xsErrorHandler');
                
2. xsErrorHandler(2, 'fsockopen(): php_network_getaddr...', '/www/web/fecshop/vendor/hightman...', 476, ...)
3. in /www/web/fecshop/vendor/hightman/xunsearch/lib/XSServer.class.php at line 476 – fsockopen('xunsearch', 8384, 0, 'php_network_getaddresses: getadd...', ...)
470471472473474475476477478479480481482                    			$host = substr($conn, 0, $pos);
            $port = intval(substr($conn, $pos + 1));
        } else {
            $host = 'unix://' . $conn;
            $port = -1;
        }
        if (($sock = @fsockopen($host, $port, $errno, $error, 5)) === false) {
            throw new XSException($error . '(C#' . $errno . ', ' . $host . ':' . $port . ')');
        }
 
        // set socket options
        $timeout = ini_get('max_execution_time');
        $timeout = $timeout > 0 ? ($timeout - 1) : 30;
                
4. in /www/web/fecshop/vendor/hightman/xunsearch/lib/XSServer.class.php at line 172 – XSServer::connect()
166167168169170171172173174175176177178                    	{
        $this->close();
        $this->_conn = $conn;
        $this->_flag = self::BROKEN;
        $this->_sendBuffer = '';
        $this->_project = null;
        $this->connect();
        $this->_flag ^= self::BROKEN;
        if ($this->xs instanceof XS) {
            $this->setProject($this->xs->getName());
        }
    }
 
                
5. in /www/web/fecshop/vendor/hightman/xunsearch/lib/XSSearch.class.php at line 57 – XSServer::open('xunsearch:8384')
51525354555657585960616263                    	 * 每次重新连接后所有的搜索语句相关设置均被还原
     * @param string $conn
     * @see XSServer::open
     */
    public function open($conn)
    {
        parent::open($conn);
        $this->_prefix = array();
        $this->_fieldSet = false;
        $this->_lastCount = false;
    }
 
    /**
                
6. in /www/web/fecshop/vendor/hightman/xunsearch/lib/XSServer.class.php at line 147 – XSSearch::open('xunsearch:8384')
141142143144145146147148149150151152153                    	 * @param XS $xs 需要捆绑的 xs 对象
     */
    public function __construct($conn = null, $xs = null)
    {
        $this->xs = $xs;
        if ($conn !== null) {
            $this->open($conn);
        }
    }
 
    /**
     * 析构函数, 关闭连接
     */
                
7. in /www/web/fecshop/vendor/hightman/xunsearch/lib/XS.class.php at line 450 – XSServer::__construct('xunsearch:8384', XS)
444445446447448449450451452453454455456                    			}
            if (count($conns) > 1) {
                shuffle($conns);
            }
            for ($i = 0; $i < count($conns); $i++) {
                try {
                    $this->_search = new XSSearch($conns[$i], $this);
                    $this->_search->setCharset($this->getDefaultCharset());
                    return $this->_search;
                } catch (XSException $e) {
                    if (($i + 1) === count($conns)) {
                        throw $e;
                    }
                
8. in /www/web/fecshop/vendor/hightman/xunsearch/lib/XS.class.php at line 186 – XS::getSearch()
180181182183184185186187188189190191192                    	 * @throw XSException 属性不存在或不可读时抛出异常
     */
    public function __get($name)
    {
        $getter = 'get' . $name;
        if (method_exists($this, $getter)) {
            return $this->$getter();
        }
 
        // throw exception
        $msg = method_exists($this, 'set' . $name) ? 'Write-only' : 'Undefined';
        $msg .= ' property: ' . get_class($this) . '::$' . $name;
        throw new XSException($msg);
                
9. in /www/web/fecshop/vendor/hightman/xunsearch/wrapper/yii2-ext/Database.php at line 91 – XSComponent::__get('search')
85868788899091929394959697                     
    /**
     * @return \XSSearch get xunsearch search object
     */
    public function getSearch()
    {
        return $this->xs->search;
    }
 
    /**
     * @return QueryBuilder
     */
    public function getQueryBuilder()
                
10. in /www/web/fecshop/vendor/hightman/xunsearch/wrapper/yii2-ext/QueryBuilder.php at line 72 – hightman\xunsearch\Database::getSearch()
66676869707172737475767778                    		if ($query->query === null) {
            $query->query = $this->buildWhere($query->where, $others);
        }
 
        $profile = $this->db->getName() . '.build#' . $query->query;
        Yii::beginProfile($profile, __METHOD__);
        $search = $this->db->getSearch();
        $search->setFuzzy($query->fuzzy)->setAutoSynonyms($query->synonyms);
        $search->setQuery($query->query);
        if (isset($others['range'])) {
            $this->buildRange($others['range']);
        }
        if (isset($others['weight'])) {
                
11. in /www/web/fecshop/vendor/hightman/xunsearch/wrapper/yii2-ext/ActiveQuery.php at line 345 – hightman\xunsearch\QueryBuilder::build(hightman\xunsearch\ActiveQuery)
339340341342343344345346347                    	 */
    private function buildSearch(&$db)
    {
        if ($db === null) {
            $db = $this->getDb();
        }
        return $this->_search = $db->getQueryBuilder()->build($this);
    }
}
                
12. in /www/web/fecshop/vendor/hightman/xunsearch/wrapper/yii2-ext/ActiveQuery.php at line 212 – hightman\xunsearch\ActiveQuery::buildSearch(hightman\xunsearch\Database)
206207208209210211212213214215216217218                    	 * If null, the DB returned by [[modelClass]] will be used.
     * @return array|ActiveRecord[] the search results. If the results in nothing, an empty array will be returned.
     */
    public function all($db = null)
    {
        $query = $this->query;
        $search = $this->buildSearch($db);
        $this->beforeSearch();
        $profile = $db->getName() . '.findAll#' . $this->query;
        Yii::beginProfile($profile, __METHOD__);
        $docs = $search->search($query);
        Yii::endProfile($profile, __METHOD__);
        return $this->populate($docs);
                
13. in /www/web/fecshop/vendor/fancyecommerce/fecshop/services/search/XunSearch.php at line 162 – hightman\xunsearch\ActiveQuery::all()
156157158159160161162163164165166167168                                        }
                }
            }
            $XunSearchQuery->orderBy(['score' => SORT_DESC]);
            $XunSearchQuery->limit($product_search_max_count);
            $XunSearchQuery->offset(0);
            $search_data = $XunSearchQuery->all();
 
            $data = [];
            foreach ($search_data as $one) {
                if (!isset($data[$one['spu']])) {
                    $data[$one['spu']] = $one;
                }
                
14. in /www/web/fecshop/vendor/fancyecommerce/fecshop/services/search/XunSearch.php at line 126 – fecshop\services\search\XunSearch::fullTearchText(['product_id', 'sku', 'spu', 'name', ...], ['$text' => ['$search' => '8888']], 1, 30, ...)
120121122123124125126127128129130131132                     
    /**
     * 得到搜索的产品列表.
     */
    protected function actionGetSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count)
    {
        $collection = $this->fullTearchText($select, $where, $pageNum, $numPerPage, $product_search_max_count);
 
        $collection['coll'] = Yii::$service->category->product->convertToCategoryInfo($collection['coll']);
        //var_dump($collection);
        //exit;
        return $collection;
    }
                
15. fecshop\services\search\XunSearch::actionGetSearchProductColl(['product_id', 'sku', 'spu', 'name', ...], ['$text' => ['$search' => '8888']], 1, 30, ...)
16. in /www/web/fecshop/vendor/fancyecommerce/fecshop/services/Service.php at line 49 – call_user_func_array([fecshop\services\search\XunSearch, 'actionGetSearchProductColl'], [['product_id', 'sku', 'spu', 'name', ...], ['$text' => ['$search' => '8888']], 1, 30, ...])
43444546474849505152535455                            } else {
            $method = 'action'.ucfirst($originMethod);
            $this->_callFuncLog[$originMethod] = $method;
        }
        if (method_exists($this, $method)) {
            $this->beginCall($originMethod, $arguments);
            $return = call_user_func_array([$this, $method], $arguments);
            $this->endCall($originMethod, $arguments);
 
            return $return;
        } else {
            throw new InvalidCallException('fecshop service method is not exit.  '.get_class($this)."::$method");
        }
                
17. in /www/web/fecshop/vendor/fancyecommerce/fecshop/services/Search.php at line 122 – fecshop\services\Service::__call('getSearchProductColl', [['product_id', 'sku', 'spu', 'name', ...], ['$text' => ['$search' => '8888']], 1, 30, ...])
116117118119120121122123124125126127128                                    if (is_array($searchLang) && !empty($searchLang)) {
                    $searchLangCode = array_keys($searchLang);
                    // 如果当前store的语言,在当前的搜索引擎中支持,则会使用这个搜索,作为支持。
 
                    if (in_array($currentLangCode, $searchLangCode)) {
 
                        return $service->getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count, $filterAttr);
                    }
                }
            }
        }
    }
 
                
18. fecshop\services\Search::actionGetSearchProductColl(['product_id', 'sku', 'spu', 'name', ...], ['$text' => ['$search' => '8888']], 1, 30, ...)
19. in /www/web/fecshop/vendor/fancyecommerce/fecshop/services/Service.php at line 49 – call_user_func_array([fecshop\services\Search, 'actionGetSearchProductColl'], [['product_id', 'sku', 'spu', 'name', ...], ['$text' => ['$search' => '8888']], 1, 30, ...])
43444546474849505152535455                            } else {
            $method = 'action'.ucfirst($originMethod);
            $this->_callFuncLog[$originMethod] = $method;
        }
        if (method_exists($this, $method)) {
            $this->beginCall($originMethod, $arguments);
            $return = call_user_func_array([$this, $method], $arguments);
            $this->endCall($originMethod, $arguments);
 
            return $return;
        } else {
            throw new InvalidCallException('fecshop service method is not exit.  '.get_class($this)."::$method");
        }
                
20. in /www/web/fecshop/vendor/fancyecommerce/fecshop/app/appfront/modules/Catalogsearch/block/index/Index.php at line 331 – fecshop\services\Service::__call('getSearchProductColl', [['product_id', 'sku', 'spu', 'name', ...], ['$text' => ['$search' => '8888']], 1, 30, ...])
325326327328329330331332333334335336337                            $where = $this->_where;
        $search_text = Yii::$app->controller->module->params['search_query'];
        $pageNum = $this->getPageNum();
        $numPerPage = $this->getNumPerPage();
        $product_search_max_count = Yii::$app->controller->module->params['product_search_max_count'];
        $filterAttr = $this->getFilterAttr();
        return Yii::$service->search->getSearchProductColl($select, $where, $pageNum, $numPerPage, $product_search_max_count, $filterAttr);
    }
    /**
     * 初始化where
     */
    protected function initWhere()
    {
                
21. in /www/web/fecshop/vendor/fancyecommerce/fecshop/app/appfront/modules/Catalogsearch/block/index/Index.php at line 50 – fecshop\app\appfront\modules\Catalogsearch\block\index\Index::getSearchProductColl()
44454647484950515253545556                            $this->getNumPerPage();
        //echo Yii::$service->page->translate->__('fecshop,{username}', ['username' => 'terry']);
        $this->initSearch();
        // change current layout File.
        //Yii::$service->page->theme->layoutFile = 'home.php';
 
        $productCollInfo = $this->getSearchProductColl();
        $products = $productCollInfo['coll'];
        $this->_productCount = $productCollInfo['count'];
        //echo $this->_productCount;
        return [
            'searchText'        => $this->_searchText,
            'title'        => $this->_title,
                
22. in /www/web/fecshop/vendor/fancyecommerce/fecshop/app/appfront/modules/Catalogsearch/controllers/IndexController.php at line 28 – fecshop\app\appfront\modules\Catalogsearch\block\index\Index::getLastData()
2223242526272829303132                            parent::init();
    }
 
    //
    public function actionIndex()
    {
        $data = $this->getBlock()->getLastData();
 
        return $this->render($this->action->id, $data);
    }
}
                
23. fecshop\app\appfront\modules\Catalogsearch\controllers\IndexController::actionIndex()
24. in /www/web/fecshop/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – call_user_func_array([fecshop\app\appfront\modules\Catalogsearch\controllers\IndexController, 'actionIndex'], [])
25. in /www/web/fecshop/vendor/yiisoft/yii2/base/Controller.php at line 157 – yii\base\InlineAction::runWithParams(['q' => '8888'])
26. in /www/web/fecshop/vendor/yiisoft/yii2/base/Module.php at line 528 – yii\base\Controller::runAction('', ['q' => '8888'])
27. in /www/web/fecshop/vendor/yiisoft/yii2/web/Application.php at line 103 – yii\base\Module::runAction('catalogsearch/index', ['q' => '8888'])
28. in /www/web/fecshop/vendor/yiisoft/yii2/base/Application.php at line 386 – yii\web\Application::handleRequest(fecshop\yii\web\Request)
29. in /www/web/fecshop/appfront/web/cn/index.php at line 90 – yii\base\Application::run()
84858687888990                     * 上面的例子就是获取cms服务的子服务article。
 */
new fecshop\services\Application($config['services']);
unset($config['services']);
 
$application = new yii\web\Application($config);
$application->run();
                
$_GET = [
    'q' => '8888',
];

$_COOKIE = [
    'PHPSESSID' => '8a01bf5152d3c1c872b97f711f399749',
    '_csrf' => '56244ed261bc77ded14456e25e2b8ecc11d0cebebce31ceb4dc7057f7d592a64a:2:{i:0;s:5:"_csrf";i:1;s:32:"1xAmBgCpeZL6-MU-gpGWhCN31hwiuJbj";}',
];

$_SESSION = [
    '__flash' => [],
    'currency_current' => 'CNY',
];

某帖子中说要在etc/hosts里添加 127.0.0.1,已添加,但是问题依旧。 然后查找到一个步骤说要跑脚本:

cd vendor/fancyecommerce/fecshop/shell/search
sh fullSearchSync.sh

但是xshell里面报错。

/usr/bin/env: php: No such file or directory
/usr/bin/env: php: No such file or directory
/usr/bin/env: php: No such file or directory
/usr/bin/env: php: No such file or directory
There are  products to process
There are  pages to process
##############ALL BEGINING###############
fullSearchSync.sh: line 17: ((: i<=: syntax error: operand expected (error token is "<=")
/usr/bin/env: php: No such file or directory
##############ALL COMPLETE###############
共收到 9 条回复 问题提问 fecshop
1楼 已删除.
Fecmall#26年前 1 个赞

先理好你的帖子:

排版说明:http://www.fecshop.com/markdown

如何发帖:http://www.fecshop.com/topic/624

对于乱七八糟的帖子一概不给于回复

Fecmall#36年前 1 个赞

自行想办法改改帖子内容,这样的乱糟糟的帖子不利于后人搜索解决问题

先回复下你的问题原因:

标题的问题,你参看第一个帖子已经解决,下面说一下你的这个报错:

/usr/bin/env: php: No such file or directory /usr/bin/env: php: No such file or directory /usr/bin/env: php: No such file or directory /usr/bin/env: php: No such file or directory There are products to process There are pages to process

原因:

fecshop的脚本执行使用的是Yii2的console,打开fecshop安装后的根目录的 yii 文件,你会发现 #!/usr/bin/env php,这说明你的php需要是可以执行使用的

因此,你在任何一个文件路径,执行命令php,是否可以执行? 如果不能执行,那么需要添加一下快捷方式

解决办法:譬如我的php的安装路径是在 /usr/local/php/bin/php ,那么我需要执行

ln -s /usr/local/php/bin/php  /usr/bin/php

将上面命令行中的 /usr/local/php/bin/php 替换成您自己的php路径即可

htony#46年前 0 个赞

谢谢回复,昨天一直没来得及整理帖子,一会儿到公司后,马上就开始整理。

Fecmall#56年前 0 个赞

@htony #4楼 问题解决了吧?

htony#66年前 0 个赞

@Fecshop #5楼 我用的是您发布在github上面的docker compose部署环境的教程进行环境部署的,这个环境集成的有PHP对吧?我尝试了其中几个位置,实在确定不了PHP的安装位置。不好意思,刚接触Linux没多久,问题比较小白。

用find命令查找PHP存在的位置如下:

/var/lib/docker/overlay2/113d******ebd1/diff/usr/local/lib/php
/var/lib/docker/overlay2/5421******f1ab/diff/usr/local/lib/php
/var/lib/docker/overlay2/5421******f1ab/diff/usr/local/php
/var/lib/docker/overlay2/5421******f1ab/diff/usr/local/php/php
/var/lib/docker/overlay2/5421******f1ab/diff/usr/local/include/php
/var/lib/docker/overlay2/5421******f1ab/diff/usr/local/bin/php
/var/lib/docker/overlay2/2697******5d58/diff/usr/local/xunsearch/sdk/php
/var/lib/docker/overlay2/3625******6c1d/diff/usr/local/etc/php
/var/lib/docker/overlay2/3625******6c1d/merged/usr/local/lib/php
/var/lib/docker/overlay2/3625******6c1d/merged/usr/local/include/php
/var/lib/docker/overlay2/3625******6c1d/merged/usr/local/etc/php
/var/lib/docker/overlay2/3625******6c1d/merged/usr/local/bin/php
/var/lib/docker/overlay2/3625******6c1d/merged/usr/local/php
/var/lib/docker/overlay2/3625******6c1d/merged/usr/local/php/php
/var/lib/docker/overlay2/cc49******fadc/diff/usr/local/lib/php
/var/lib/docker/overlay2/cc49******fadc/diff/usr/local/include/php
/var/lib/docker/overlay2/cc49******fadc/diff/usr/local/etc/php
/var/lib/docker/overlay2/3c7a******bacb/diff/usr/local/etc/php
/var/lib/docker/overlay2/498b******ac8a/diff/usr/local/etc/php

Fecmall#76年前 0 个赞

如果是docker compose 不应该出现这个问题,上面说错了,百度搜索了一下/usr/bin/env: php: No such file or directory

找到资料:

https://blog.csdn.net/yigeshouyiren/article/details/39519281

按照docker 安装,不应该出这个问题,您自己找找原因吧,第一听说docker出这个问题的

你的docker 是linux下面,还是win下面?

Fecmall#86年前 0 个赞

新问题,开新帖,方便以后讨论,搜索

htony#96年前 0 个赞

docker是linux下面的。我看了您发的那个页面,估计是可能和我中间有些步骤图省事把Linux文件传到本机win系统上修改有关系。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics