Php cURL调用或Symfony2任务执行是否有超时?

Php cURL调用或Symfony2任务执行是否有超时?,php,symfony,curl,symfony-2.6,Php,Symfony,Curl,Symfony 2.6,我只是想找出执行Symfony2任务是否有任何超时或最大执行时间。为什么?每当我执行任务pdone:sync时,它都会随着以下日志停止: Symfony > pdone:sync [Symfony\Component\Debug\Exception\ContextErrorException] Notice: Undefined offset: 2000 pdone:sync The command terminated with an error status (1) 这是

我只是想找出执行Symfony2任务是否有任何
超时
最大执行时间
。为什么?每当我执行任务
pdone:sync
时,它都会随着以下日志停止:

Symfony > pdone:sync

  [Symfony\Component\Debug\Exception\ContextErrorException]
  Notice: Undefined offset: 2000

pdone:sync
The command terminated with an error status (1)
这是我的代码,它是作为服务从task调用的,第二个SOQL查询正好返回6911项,所以它应该插入6911项,而不是停止在2000项,为什么?那里发生了什么?有什么建议、帮助或想法吗

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface as Container;
use PDI\PDOneBundle\Entity;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\RequestStack;

class SyncController extends Controller
{
    private $_em;
    private $_container;
    private $_rs;

    public function __construct(Container $container, EntityManager $em, RequestStack $rs)
    {
        $this->_container = $container;
        $this->_em = $em;
        $this->_rs = $rs;
    }

    public function syncVeevaData()
    {
        $em = $this->_em;
        $request = $this->_rs->getCurrentRequest();
        $container = $this->_container;

        // Will need this in the whole function so lets declare it here
        $now = new \DateTime();

        $expireTime = clone $now;
        $expireTime = $expireTime->modify('+1 week');

        // Request veeva token and instance URL
        $token_url = $container->getParameter('login_uri')."/services/oauth2/token";

        $params = "grant_type=".$container->getParameter('grant_type')
            ."&client_id=".$container->getParameter('client_id')
            ."&username=".$container->getParameter('veeva_username')
            ."&password=".$container->getParameter('veeva_password')
            ."&client_secret=".$container->getParameter('client_secret')
            ."&redirect_uri=".urlencode($container->getParameter('redirect_uri'));

        $curl = curl_init($token_url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $params);

        $json_response = curl_exec($curl);
        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ($status != 200) {
            $respObj['error'] = "Error: call to token URL $token_url failed with status $status, response $json_response, curl_error ".curl_error(
                    $curl
                ).", curl_errno ".curl_errno($curl);

            return $respObj;
        }

        curl_close($curl);

        $response = json_decode($json_response, true);

        $veevaToken = $respObj['access_token'] = $response['access_token'];
        $instanceUrl = $respObj['instance_url'] = $response['instance_url'];

        if (!isset($veevaToken) || $veevaToken == "") {
            $respObj['error'] = "Error - access token missing from response!";

            return $respObj;
        }

        if (!isset($instanceUrl) || $instanceUrl == "") {
            $respObj['error'] = "Error - instance URL missing from response!";

            return $respObj;
        }

        // Request reps and sync against DB
        $soqlQuery1 = "SELECT Id,FirstName,LastName,Username,Email,LastModifiedDate FROM User";
        $soqlUrl1 = $instanceUrl.'/services/data/v28.0/query/?q='.urlencode($soqlQuery1);

        $curl = curl_init($soqlUrl1);

        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: OAuth $veevaToken"));

        $jsonResponse = curl_exec($curl);

        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        if ($status != 200) {
            $respObj['error'] = "Error: call to token URL $token_url failed with status $status, response $json_response, curl_error ".curl_error(
                    $curl
                ).", curl_errno ".curl_errno($curl);

            return $respObj;
        }

        curl_close($curl);

        $soqlObj1 = json_decode($jsonResponse, true);

        for ($i = 0; $i < $soqlObj1['totalSize']; $i++) {
            $entReps = $em->getRepository('PDOneBundle:Representative')->findOneBy(
                array(
                    'veeva_rep_id' => $soqlObj1['records'][$i]['Id'],
                )
            );

            if (!$entReps) {
                // if there is no reps, then we add
                $newReps = new Entity\Representative();

                // we set the values from veeva
                $newReps->setVeevaRepId($soqlObj1['records'][$i]['Id']);
                $newReps->setEmail($soqlObj1['records'][$i]['Email']);
                $newReps->setFirst($soqlObj1['records'][$i]['FirstName']);
                $newReps->setLast($soqlObj1['records'][$i]['LastName']);
                $newReps->setUsername($soqlObj1['records'][$i]['Username']);
                $newReps->setLastLoginAt($now);
                $newReps->setLastSyncAt($now);
                $newReps->setDisplayName(
                    $soqlObj1['records'][$i]['FirstName'].' '.$soqlObj1['records'][$i]['LastName']
                );
                $newReps->setRepType("VEEVA");

                $em->persist($newReps);
                $em->flush();

                // Put new reps into $newRepsArr
                $repsArr[$newReps->getId()] = $newReps->getVeevaRepId();
            } else {
                $lastModifiedDate = new \DateTime(
                    $soqlObj1['records'][$i]['LastModifiedDate']
                );

                if ($lastModifiedDate > $entReps->getLastSyncAt()) {
                    // obtained a reps, we update its data
                    $entReps->setEmail($soqlObj1['records'][$i]['Email']);
                    $entReps->setFirst($soqlObj1['records'][$i]['FirstName']);
                    $entReps->setLast($soqlObj1['records'][$i]['LastName']);
                    $entReps->setUsername($soqlObj1['records'][$i]['Username']);
                    $entReps->setLastLoginAt($now);
                    $entReps->setLastSyncAt($now);
                    $entReps->setDisplayName(
                        $soqlObj1['records'][$i]['FirstName'].' '.$soqlObj1['records'][$i]['LastName']
                    );
                    $entReps->setRepType("VEEVA");

                    // Put updated reps into $updRepsArr
                    $repsArr[$entReps->getId()] = $entReps->getVeevaRepId();
                }
            }
        }

        $em->flush();

        // Get territories and sync against DB
        $soqlQuery2 = "SELECT Id,Name,LastModifiedDate FROM Territory";
        $soqlUrl2 = $instanceUrl.'/services/data/v28.0/query/?q='.urlencode($soqlQuery2);

        $curl = curl_init($soqlUrl2);

        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: OAuth $veevaToken"));

        $jsonResponse = curl_exec($curl);

        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        if ($status != 200) {
            $respObj['error'] = "Error: call to token URL $token_url failed with status $status, response $json_response, curl_error ".curl_error(
                    $curl
                ).", curl_errno ".curl_errno($curl);

            return $respObj;
        }

        curl_close($curl);

        $soqlObj2 = json_decode($jsonResponse, true);

        for ($i = 0; $i < $soqlObj2['totalSize']; $i++) {
            $entTerritory = $em->getRepository('PDOneBundle:Territory')->findOneBy(
                array(
                    'veeva_territory_id' => $soqlObj2['records'][$i]['Id']
                )
            );

            if (!$entTerritory) {
                // if there is no territory, then we add
                $newTerritory = new Entity\Territory();

                // we set the values from veeva
                if ($soqlObj2['records'][$i]['Id'] !== null || $soqlObj2['records'][$i]['Id'] !== "") {
                    $newTerritory->setVeevaTerritoryId($soqlObj2['records'][$i]['Id']);
                    $newTerritory->setName($soqlObj2['records'][$i]['Name']);

                    $em->persist($newTerritory);
                    $em->flush();
                }

                $terrArr[] = $newTerritory->getId();
                $terrFailArr[] = $soqlObj2['records'][$i]['Name'];
            } else {
                $lastModifiedDate = new \DateTime(
                    $soqlObj2['records'][$i]['LastModifiedDate']
                );

                if ($lastModifiedDate > $entTerritory->getUpdatedAt()) {
                    // obtained a territory, we update its data
                    $entTerritory->setName($soqlObj2['records'][0]['Name']);
                }

                $terrArr[] = $entTerritory->getId();
            }
        }

        $em->flush();

        return $respObj;
    }
}
使用Symfony\Bundle\FrameworkBundle\Controller\Controller;
使用Symfony\Component\DependencyInjection\ContainerInterface作为容器;
使用PDI\PDOneBundle\Entity;
使用条令\ORM\EntityManager;
使用Symfony\Component\HttpFoundation\RequestStack;
类SyncController扩展控制器
{
私人美元;
私人$\集装箱;
私人美元;
公共函数构造(Container$Container、EntityManager$em、RequestStack$rs)
{
$this->_container=$container;
$this->_em=$em;
$this->\u rs=$rs;
}
公共函数syncVeevaData()
{
$em=$this->\u em;
$request=$this->\u rs->getCurrentRequest();
$container=$this->\u container;
//在整个函数中都需要它,所以让我们在这里声明它
$now=new\DateTime();
$expireTime=clone$now;
$expireTime=$expireTime->modify(“+1周”);
//请求veeva令牌和实例URL
$token\u url=$container->getParameter('login\u uri')。“/services/oauth2/token”;
$params=“grant\u type=”.$container->getParameter('grant\u type'))
.“&client\u id=“.$container->getParameter('client\u id'))
.“&username=“.$container->getParameter('veeva_username'))
.“&password=“.$container->getParameter('veeva_password'))
.“&client\u secret=“.$container->getParameter('client\u secret'))
.“&redirect_uri=“.urlencode($container->getParameter('redirect_uri'));
$curl=curl\u init($token\u url);
curl_setopt($curl,CURLOPT_头,false);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_POST,true);
curl_setopt($curl,CURLOPT_POSTFIELDS,$params);
$json\u response=curl\u exec($curl);
$status=curl\u getinfo($curl,CURLINFO\u HTTP\u代码);
如果($status!=200){
$respObj['error']=“错误:调用令牌URL$token\u URL失败,状态为$status,响应$json\u response,curl\u error”。curl\u错误(
$curl
)“,curl_errno.”curl_errno($curl);
返回$respObj;
}
curl_close($curl);
$response=json\u decode($json\u response,true);
$veevaToken=$respObj['access_token']=$response['access_token'];
$instanceUrl=$respObj['instance\u url']=$response['instance\u url'];
如果(!isset($veevaToken)| |$veevaToken==“”){
$respObj['error']=“错误-响应中缺少访问令牌!”;
返回$respObj;
}
如果(!isset($instanceUrl)| |$instanceUrl==“”){
$respObj['error']=“错误-响应中缺少实例URL!”;
返回$respObj;
}
//请求重复并与数据库同步
$soqlQuery1=“从用户选择Id、FirstName、LastName、用户名、电子邮件、LastModifiedDate”;
$soqlUrl1=$instanceUrl.'/services/data/v28.0/query/?q='.urlencode($soqlQuery1);
$curl=curl\u init($soqlUrl1);
curl_setopt($curl,CURLOPT_头,false);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_HTTPHEADER,数组(“授权:OAuth$veevaToken”);
$jsonResponse=curl\u exec($curl);
$status=curl\u getinfo($curl,CURLINFO\u HTTP\u代码);
如果($status!=200){
$respObj['error']=“错误:调用令牌URL$token\u URL失败,状态为$status,响应$json\u response,curl\u error”。curl\u错误(
$curl
)“,curl_errno.”curl_errno($curl);
返回$respObj;
}
curl_close($curl);
$soqlObj1=json_decode($jsonResponse,true);
对于($i=0;$i<$soqlObj1['totalSize'];$i++){
$entReps=$em->getRepository('PDOneBundle:Representative')->findOneBy(
排列(
'veeva_rep_id'=>$soqlObj1['records'][$i]['id'],
)
);
如果(!$entReps){
//如果没有代表,那么我们添加
$newReps=新实体\代表();
//我们从veeva设置值
$newReps->setveevaredip($soqlObj1['records'][$i]['Id']);
$newReps->setEmail($soqlObj1['records'][$i]['Email']);
$newReps->setFirst($soqlObj1['records'][$i]['FirstName']);
$newReps->setLast($soqlObj1['records'][$i]['LastName']);
$newReps->setUsername($soqlObj1['records'][$i]['Username']);
$newReps->setLastLoginAt($now);
$newReps->setLastSyncAt($now);
$newReps->setDisplayName(
$soqlObj1['records'][$i]['FirstName'].'。$soqlObj1['records'][$i]['LastName']
);
$newReps->setRepType(“VEEVA”);
$em->persist($newReps);
$em->flush();
//将新销售代表放入$newRepsArr
$repsArr[$newReps->getId()]=$newReps->getVeevaRepId();
}否则{
$lastModifiedDate=new\DateTime(
$soqlObj1['records'][$i]['LastModifiedDate']
);
如果($lastModifiedDate>$entReps->getLastSyncAt()){
//获得了一个代表,我们更新了它的数据
$entReps->setEmail($soqlObj1['records'][$i]['Email']);
$entReps->setFirst($soqlObj1['records'][$i]['FirstName']);
$entReps->setLast($soqlObj1['records'][$i]['LastName']);
$entReps->setUser