<p>The general process of debugging inside the container is the same as debugging outside of one.  The only thing that you generally need to know is that you can use <code>docker exec</code> to attach a bash shell inside a running container, or override the command with <code>--entrypoint</code> to launch bash instead, and then run the script manually.</p>

<p>At that point, your question becomes "How do I debug slow execution times in a PHP script?".  That is not really in scope for this site, but you can start with a few basic things: add print statements or attach a profiler to see where things are getting slow, and then narrow it down from there.</p>

CC BY-SA 4.0
2018-11-21T22:55:36.380Z
2018-11-21T22:55:36.380Z
Xiong Chiamiov
<p>I've recently migrated an event subscription service called by a bash script from Ubuntu, into a Dockerised container.</p>

<p>The Docker image I am using is: <code>FROM php:7.1-apache</code></p>

<p>The script itself is pretty straightforward:</p>

<pre><code>#!/bin/bash

DIR="$(dirname $0)"
OUTPUT=""

while true
do
    OUTPUT=""
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:issueEvents)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processCustomerAccountEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processProductionOrderEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processWebEnquiryEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processWebOrderEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processWebQuoteEventSubscriptions)

    if [ -z "$OUTPUT" ]; then
        sleep 10
    fi
done
</code></pre>

<p>A complete round trip from event subscription to processing would take about 30 seconds on the host OS. Inside a container it is taking around 10 minutes.</p>

<p>My initial suspicion was that DNS was slowing things down, but I've installed <code>dnsutils</code> and the lookup times are the same both inside and outside the container.</p>

<p>I'd like advice regarding how I'd go about investigating the cause of this slowdown.</p>

<docker><php><bash>
How can I diagnose php cli command execution time inside a docker container
pcgben
# How can I diagnose php cli command execution time inside a docker container

(Asked by: username_0 on 2018-11-07)

I've recently migrated an event subscription service called by a bash script from Ubuntu, into a Dockerised container.
The Docker image I am using is: FROM php:7.1-apache
The script itself is pretty straightforward:
#!/bin/bash

DIR="$(dirname $0)"
OUTPUT=""

while true
do
    OUTPUT=""
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:issueEvents)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processCustomerAccountEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processProductionOrderEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processWebEnquiryEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processWebOrderEventSubscriptions)
    OUTPUT=$OUTPUT$(php $DIR/../bin/cli.php bash:v1:processWebQuoteEventSubscriptions)

    if [ -z "$OUTPUT" ]; then
        sleep 10
    fi
done

A complete round trip from event subscription to processing would take about 30 seconds on the host OS. Inside a container it is taking around 10 minutes.
My initial suspicion was that DNS was slowing things down, but I've installed dnsutils and the lookup times are the same both inside and outside the container.
I'd like advice regarding how I'd go about investigating the cause of this slowdown.

**Tags:** docker, php, bash


---

## 1 answers

### Answer by username_1 on 2018-11-21. Score: 1

The general process of debugging inside the container is the same as debugging outside of one. The only thing that you generally need to know is that you can use `docker exec` to attach a bash shell inside a running container, or override the command with `--entrypoint` to launch bash instead, and then run the script manually.

At that point, your question becomes "How do I debug slow execution times in a PHP script?". That is not really in scope for this site, but you can start with a few basic things: add print statements or attach a profiler to see where things are getting slow, and then narrow it down from there.


---

