Repository navigation
PHP fix 7/10: Maximum execution time exceeded — process bounded batches with a checkpoint #17
vistabylara-dev
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
انتهاء مهلة التنفيذ قد يعني أن المهمة أكبر من طلب واحد. قسّم العمل إلى دفعات محدودة واحفظ موضع التقدم بعد نجاح المعالجة.
Free code series · Topic 14/50 · PHP fix 7/10
The problem
A long sync tries to handle every item in one request. Increasing a timeout may hide slow requests or runaway loops. Bounded work makes progress and failure easier to reason about.
Where this belongs in Shopify
PHP runs in an external app, integration service, or server you control. Shopify themes use Liquid, HTML, CSS, and JavaScript; do not paste this PHP into a theme section or Custom Liquid block. If a third-party app owns the failing server, share a sanitized error with that app's support team.
Placement and free suggested code
Save as batch-demo.php in a PHP development directory. This is a pure simulation over five integers, not a production queue or Shopify pagination implementation.
batch-demo.php
Verify before using it
The first run processes items 1 and 2 and returns offset 2. A second call with offset 2 processes 3 and 4. Offset 4 processes 5; offset 5 does nothing. Test failure midway before adapting this pattern. Production code needs a durable checkpoint, stable ordering, concurrency control, and idempotent operations.
What was checked for this guide: The demo ran in a PHP WebAssembly CLI runtime. Local fixture checks passed; this is not a test of your host, store, production workflow, or every failure mode.
Precautions and rollback
The demo does not persist progress. A retry can repeat work done before a failure: use an appropriate unique operation key or transactional design, especially for orders. Use the API's actual cursor when paginating. One slow item can still exceed a timeout; configure bounded outbound requests. Web server and proxy deadlines may differ from PHP's limit.
Back up or commit the existing application before adapting anything. Test on a development copy with dummy data. Restore the previous application version if behavior regresses; reverting code does not undo database writes or external actions. These are educational suggestions, not a universal drop-in repair.
Check the ecommerce workflow
After adapting a fix, verify the affected operation from input to its intended result in your test environment. Check failure handling as well as success. Do not mark a sale or analytics purchase event merely because a PHP script finished. Payment/order state and analytics reporting need their own checks, and repeated requests must not duplicate side effects.
Official references
Share your error and join the free discussion
Comment with the exact error text, PHP version, whether this is your own app or a third-party app, and a short sanitized code sample. Remove passwords, tokens, customer details, and private server paths. What happened just before the error?
Need free Shopify guidance or a free consultation? Call +971 50 799 4292 or message Dr Lara on WhatsApp.
Free guidance. No commitment. No package to sell.
Dr Lara · Dubai, UAE
All reactions