By default in app_dev.php
you have the profiler bar, click on the timer and you will have a good start to debug (timeline with main/sub request, etc)
Symfony 20 Minute Page Load Times
-
05-06-2023 - |
Question
Does anyone have a clue why in the world I would be getting 20 minute page load times in dev in Symfony2? It just randomly happens to me. One day I will get fast load times, the next day I am twiddling my thumbs waiting for a page to load. What can I check/disable/enable/etc? Thanks!
Here is my latest page load:
Time: 298068 ms
Here is the Entity for 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;
Here is my controller method 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(),
);
No correct solution
OTHER TIPS
The issue was in the OneToMany relationship code where it says fetch="EAGER". This was pulling in all sorts of unnecessary associations and db queries. When I removed it, the db queries went down to 4 per page instead of 4000.
Are you using x-debug or any PHP level profiling? You've either got some form of recursion happening or one of the steps in the security\http\firewall
process is taking a very long time to complete.
My suggestion would be
Look at your stack-trace and find anywhere there are highly repeated events around the
security\http\firewall
code and investigate if they existQuickly step through your code using x-debug, and find where the delay is occurring. With a few page reloads you should be able to step into the section which is causing the long page load times.
If you are using profiling, make sure your created files aren't ridiculously verbose. I've seen this long page load issue happen before due to profiling, where each page load would create a 20Gb+ profiling file.