Symfony 20分钟页面加载时间

时间:2014-03-04 19:33:04

标签: symfony page-load-time

有没有人知道为什么在世界上我会在Symfony2中的dev中获得20分钟的页面加载时间?它只是随机发生在我身上。有一天,我会得到快速的加载时间,第二天我在翻阅我的拇指等待页面加载。我可以检查/禁用/启用/ etc?谢谢!

这是我最新的页面加载:

时间:298068毫秒

Screen Shot of Issue

以下是PurchaseOrder的实体

 /**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="archived_po_number", type="string", length=50, nullable=true)
 * @Common\Versioned
 */
private $archived_po_number;

/**
 * @var string
 *
 * @ORM\Column(name="name", type="string", length=50, nullable=true)
 * @Common\Versioned
 */
private $name;

/**
 * @var string
 *
 * @ORM\Column(name="show_locations", type="string", length=1, nullable=true)
 * @Common\Versioned
 */
private $show_locations;

/**
 * @var integer
 *
 * @ORM\Column(name="freight", type="decimal", precision=10, scale=2, nullable=true)
 * @Common\Versioned
 */
private $freight;

/**
 * @var integer
 *
 * @ORM\Column(name="pallets", type="integer", nullable=true)
 * @Common\Versioned
 */
private $pallets;

/**
 * @var integer
 *
 * @ORM\Column(name="boxes", type="integer", nullable=true)
 * @Common\Versioned
 */
private $boxes;

/**
 * @var text
 * @ORM\Column(name="internal_notes", type="text", nullable=true)
 * @Common\Versioned
 */
private $internal_notes;

/**
 * @var text
 * @ORM\Column(name="sales_rep_notes", type="text", nullable=true)
 * @Common\Versioned
 */
private $sales_rep_notes;

/**
 * @var string
 *
 * @ORM\Column(name="custom_purchase_order_number", type="string", length=255, nullable=true)
 * @Common\Versioned
 */
private $custom_purchase_order_number;

/**
 * @ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="purchase_order_class", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $purchase_order_class;

/**
 * @ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="generated_by_location", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $generated_by_location;

/**
 * @ORM\ManyToOne(targetEntity="WIC\InventoryLocationBundle\Entity\InventoryLocation", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="receive_location", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $receive_location;

/**
 * @ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="company_name", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $company_name;

/**
 * @ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="ship_to", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $ship_to;

/**
 * @ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="bill_to", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $bill_to;

/**
 * @ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="payment_terms", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $payment_terms;

/**
 * @ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="fob", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $fob;

/**
 * @ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="ship_via", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $ship_via;

/**
 * @var datetime
 *
 * @ORM\Column(name="ship_by", type="datetime", nullable=true)
 * @Common\Versioned
 */
private $ship_by;

/**
 * @var datetime
 *
 * @ORM\Column(name="cancel_by", type="datetime", nullable=true)
 * @Common\Versioned
 */
private $cancel_by;

/**
 * @var datetime
 *
 * @ORM\Column(name="due_by", type="datetime", nullable=true)
 * @Common\Versioned
 */
private $due_by;

/**
 * @var string
 *
 * @ORM\Column(name="nbt", type="string", length=2, nullable=true)
 * @Common\Versioned
 */
private $nbt;

/**
 * @ORM\OneToMany(targetEntity="WIC\PurchaseOrderLineItemBundle\Entity\PurchaseOrderLineItem", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
 */
protected $purchaseOrderLineItem;

/**
 * @ORM\OneToMany(targetEntity="WIC\PurchaseOrderBundle\Entity\PurchaseOrderCharge", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
 */
protected $purchaseOrderCharge;

/**
 * @ORM\OneToMany(targetEntity="WIC\PurchaseOrderBundle\Entity\PurchaseOrderPayment", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
 */
protected $purchaseOrderPayment;

/**
 * @ORM\ManyToOne(targetEntity="WIC\SupplierBundle\Entity\Supplier", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
protected $supplier;

/**
 * @ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="status_id", referencedColumnName="id", nullable=true)
 * @Common\Versioned
 */
private $status;

/**
 * @ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
 * @ORM\JoinColumn(name="created_by", referencedColumnName="id")
 * @Common\Blameable(on="create")
 */
private $createdBy;

/**
 * @ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
 * @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
 * @Common\Blameable(on="update")
 */
private $updatedBy;

/**
 * @ORM\ManyToOne(targetEntity="WIC\AccountBundle\Entity\Account", inversedBy="purchaseOrders")
 * @ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=false)
 * @Common\Versioned
 * @Common\Blameable(on="create")
 */
protected $account;

/**
 * @var datetime $created
 *
 * @Common\Timestampable(on="create")
 * @ORM\Column(type="datetime")
 */
private $created;

/**
 * @var datetime $updated
 *
 * @Common\Timestampable(on="update")
 * @ORM\Column(type="datetime", nullable=true)
 */
private $updated;

/**
 * @ORM\Column(name="deletedAt", type="datetime", nullable=true)
 */
private $deletedAt;

这是我的控制器方法listAction()

    // verify access
    if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
        $classIdentity = new ObjectIdentity('class', 'WIC\\PurchaseOrderBundle\\Entity\\PurchaseOrder');
        if (false === $this->get('security.context')->isGranted('VIEW', $classIdentity)) {
            throw new AccessDeniedException('Only an admin user has access to this section...');
        }
    }

    // get user's account
    $account = $this->getUser()->getAccount();

    $search_form = $this->createForm(new PurchaseOrderSearchType());

    $em = $this->getDoctrine()->getManager();

    if ($request->isMethod('POST')) {
        $search_form->bind($request);
        // if ($search_form->isValid()) {
        $data = $search_form->getData();
        $purchaseOrders = $em->getRepository('WICPurchaseOrderBundle:PurchaseOrder')->getListBy($data);
        // }
    } else {

        if($this->get('request')->query->get('letter')){

        }else{

        }

        // Set the up the pagination statement...
        $em = $this->getDoctrine()->getManager();
        $dql   = "SELECT p FROM WIC\PurchaseOrderBundle\Entity\PurchaseOrder p WHERE p.account=:account_id ORDER BY p.created desc";
        $query = $em->createQuery($dql);
        $query->setParameters(array(
            'account_id' => $account->getId(),
        ));

        $paginator  = $this->get('knp_paginator');
        $paginatorObject = $paginator->paginate(
            $query,
            $this->get('request')->query->get('page', 1),25
        );

        // $purchaseOrders = $em->getRepository('WICPurchaseOrderBundle:PurchaseOrder')->findByAccount($account->getId(),array('id' => 'DESC'));
    }

    return array(
        'heading' => 'Purchase Order',
        'sidebarLeftTitle'=>'Purchase Order Menu',
        'purchaseOrders' => $paginatorObject,
        'search_form' => $search_form->createView(),
    );

3 个答案:

答案 0 :(得分:1)

默认情况下,app_dev.php你有探查器栏,点击计时器,你将有一个良好的开始调试(主/子请求的时间轴等)

答案 1 :(得分:1)

问题出在OneToMany关系代码中,其中fetch =“EAGER”。这引发了各种不必要的关联和数据库查询。当我删除它时,数据库查询下降到每页4个而不是4000个。

答案 2 :(得分:0)

您使用的是x-debug还是任何PHP级别的分析?你要么发生某种形式的递归,要么security\http\firewall过程中的一个步骤需要很长时间才能完成。

我的建议是

  • 查看堆栈跟踪,找到security\http\firewall代码周围高度重复的事件,并调查它们是否存在

  • 使用x-debug快速单步执行代码,找到发生延迟的位置。通过几次页面重新加载,您应该能够进入导致长页面加载时间的部分。

  • 如果您正在使用性能分析,请确保您创建的文件不是非常冗长。我已经看到这个长页面加载问题发生在 due 到分析之前,其中每个页面加载会创建一个20Gb +分析文件。