Zend解析器无法解析为文件

时间:2017-06-29 07:48:17

标签: php zend-framework

我最近将一个应用程序从一个服务器移动到另一个服务器并且遇到了问题。它不再在新服务器上工作,我也不知道为什么。

非常感谢任何帮助。

我认为错误是:

<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Application;

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            // The following is a route to simplify getting started creating
            // new controllers and actions without needing to create a new
            // module. Simply drop new controllers in, and you can access them
            // using the path /application/:controller/:action
            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/application',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
            //Add route delete a request.
            'delete-request' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/delete-request[/:requestId][/]',
                    'constraints' => array(
                        'requestId' => '[0-9]+'
                    ),
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'deleteRequest',
                    ),
                ),
            ),
            'change-status' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/change-status[/:requestId][/to/:active][/]',
                    'constraints' => array(
                        'requestId' => '[0-9]+',
                        'active' => '[0-9]+'
                    ),
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'changeStatus',
                    ),
                ),
            ),
            'create-new-request' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/create-new-request',
                    'constraints' => array(
                    ),
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'createNewRequest',
                    ),
                ),
            ),
            'fire-curl-requests-web' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/fire-curl-requests',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller\Command',
                        'controller'    => 'FireCurlRequest',
                        'action'        => 'index',
                    ),
                ),
            ),
            'redirect' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/redirect',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller\Command',
                        'controller'    => 'FireCurlRequest',
                        'action'        => 'redirect',
                    ),
                ),
            ),
        ),
    ),
    'console' => array(
        'router' => array(
            'routes' => array(
                'fire-curl-requests' => array(
                    'options' => array(
                        'route' => 'fire-curl-requests',
                        'defaults' => array(
                            '__NAMESPACE__' => 'Application\Controller\Command',
                            'controller'    => 'FireCurlRequest',
                            'action'        => 'index',
                        ),
                    ),
                ),
            )
        )
    ),
    'service_manager' => array(
        'abstract_factories' => array(
            'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
            'Zend\Log\LoggerAbstractServiceFactory',
        ),
        'factories' => array(
            'translator' => 'Zend\Mvc\Service\TranslatorServiceFactory',
        ),
    ),
    'translator' => array(
        'locale' => 'en_US',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => Controller\IndexController::class,
            'Application\Controller\Command\FireCurlRequest' => Controller\Command\FireCurlRequest::class
        ),
    ),
    'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
);

module.config.php

&#13;
&#13;
<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Application\Controller\Command;

use Zend\Db\Sql\Sql;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\Parameters;
use Zend\Validator\ValidatorChain;
use Zend\View\Model\ViewModel;

/**
 * Class IndexController
 * @package Application\Controller
 */
class FireCurlRequest extends AbstractActionController
{
    /**
     * @var bool
     */
    protected $adapter = false;
    /**
     * @var string
     */
    private $requestHeadersTable = 'request_headers';
    /**
     * @var string
     */
    private $requestSentTable = 'request_sent';

    /**
     * @return ViewModel
     */
    public function indexAction()
    {


        $requests = $this->getAllRequests();
        foreach ($requests as $request) {

            /** Check if already made nr of request is lower than the total allowed  */
            if ($request['request_count'] <= $request['sum']) {
                continue;
            }

            $requestStart = new \DateTime($request['modified']);

            $fromHour = $this->getStartHourForCurrentTime($requestStart);
            $toHour = new \DateTime('now');
            $sentThisHour = 0;
            $alreadySent = $this->getAlreadySentRequestForRequest($request['id']);

            foreach ($alreadySent as $sent) {
                if ($this->isBetweenDates($fromHour->format('Y-m-d H:i'), $toHour->format('Y-m-d H:i'), $sent['created'])) {
                    $sentThisHour += $sent['request_count_sent'];
                }
            }
            if ($request['request_hour_count'] >= $sentThisHour) {
                $leftToSentThisHour = $request['request_hour_count'] - $sentThisHour;
                $strtotimeToHour = strtotime($fromHour->format('Y-m-d H:i')) + 60*60;
                $currentstrtotime = strtotime('now');
                $secondsUntilHour = $strtotimeToHour - $currentstrtotime;
                $minutesLeft = (int)ceil(($secondsUntilHour / 60));

                $curlsToExecuteNow = ceil($leftToSentThisHour / $minutesLeft);
                $sentCurlRequest = 0;
                for ($i=1; $i<=$curlsToExecuteNow; $i++) {
                    /** Send curls */
                    $curlFlag = $this->doCurlRequest($request);
                    if ($curlFlag) {
                        $sentCurlRequest++;
                    }
                }

                if (!empty($sentCurlRequest)) {
                    $this->saveCurlRequests($request, $sentCurlRequest);
                }
            }
        }
        die('curl sent');
    }

    /**
     * @param $request
     * @param $sentCurlRequest
     * @return bool
     */
    public function saveCurlRequests($request, $sentCurlRequest)
    {
        try {
            $sql = new Sql($this->getAdapter());
            $sql->setTable($this->requestSentTable);
            $action = $sql->insert()
                ->values(array(
                    'request_header_id' => $request['id'],
                    'request_count_sent' =>  $sentCurlRequest
                ));
            $statement = $sql->prepareStatementForSqlObject($action);
            $statement->execute();
            return true;
        } catch (\Exception $ex) {
            return false;
        }
    }

    /**
     * @param $request
     * @return bool
     */
    public function doCurlRequest($request)
    {
        try {




            $ch = curl_init($request['request_url']);

            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_REFERER, "http://ihouseumail.com");
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
            curl_exec($ch);
            curl_close($ch);
            return true;
        } catch (\Exception $ex) {
            return false;
        }
    }

    public function redirectAction()
    {
        $url = urldecode($_GET['url']);
        header( 'Location:' . $url ) ;
        exit;
    }

    /**
     * @param $requestId
     * @return \Zend\Db\Adapter\Driver\ResultInterface
     */
    private function getAlreadySentRequestForRequest($requestId)
    {
        $requests = array();
        $sql = new Sql($this->getAdapter());
        $select = $sql->select( $this->requestSentTable)
            ->where('request_header_id = ' . $requestId);
        $statement = $sql->prepareStatementForSqlObject($select) ;
        return $statement->execute();
    }

    /**
     * @param $startDate
     * @param $endDate
     * @param $dateToCheck
     * @return bool
     */
    public function isBetweenDates($startDate, $endDate, $dateToCheck)
    {
        if (($dateToCheck > $startDate) && ($dateToCheck < $endDate)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @param $requestStart
     * @return \DateTime
     */
    public function getStartHourForCurrentTime($requestStart)
    {
        $nextHour = strtotime($requestStart->format('Y-m-d H:i')) + 60*60 ;
        $currentTime = strtotime('now');

        if ($currentTime > $nextHour) {
            $requestStart = new \DateTime(date('Y-m-d H:i', $nextHour));
            return $this->getStartHourForCurrentTime($requestStart);
        }
        return $requestStart;
    }

    /**
     * @return array
     */
    private function getAllRequests()
    {
        $requests = array();
        $sql = new Sql($this->getAdapter());
        $select = $sql->select( $this->requestHeadersTable)->where('active = 1');
        $statement = $sql->prepareStatementForSqlObject($select) ;
        $results = $statement->execute();
        foreach ($results as $result) {
            $query = $this->getAdapter()->query('SELECT SUM(request_count_sent) as sum FROM request_sent WHERE request_header_id = ' . $result['id']);
            $sum = $query->execute()->next();
            $requestArray = array_merge($result, $sum);
            $requests[] = $requestArray;
        }
        return $requests;
    }

    /**
     * @return array|bool|object
     */
    private function getAdapter()
    {
        if (!$this->adapter) {
            $sm = $this->getServiceLocator();
            $this->adapter = $sm->get('Zend\Db\Adapter\Adapter');
        }
        return $this->adapter;
    }
}
&#13;
&#13;
&#13;

FireCurlRequest.php

&#13;
&#13;
{{1}}
&#13;
&#13;
&#13;

0 个答案:

没有答案