Jump to content

Recommended Posts

I have a script which takes user parameters and creates PDF catalogs that can't always finish.  I think the bottleneck is a PHP or Apache configuration setting and ran some tests, but I don't know what to make of the results.

 

I started with the following settings and ran the same parameters each time:

 

Apache Timeout: 30

PHP max_execution_time: 30

PHP memory_limit: 8M

 

In each of 5 runs the script was cut short between 30 and 32s of execution time and used between .5MB and 6.5MB of memory.

 

I then changed PHP's max_execution_time to 10.

 

In each of 3 runs the script was cut short between 30 and 32s of execution time and used between .5MB and 1.5MB of memory.

 

I then changed PHP's memory_limit to 1M.

 

In each of 3 runs the script was cut short between 30 and 32s of execution time and I had one run that reported 9.5MB of used memory.

 

I then changed Apache's Timeout to 10.

 

In each of 2 runs the script was cut short between 10 and 12s of execution time and had memory usages of 6.14MB and 9.15MB.

 

So at this point I thought, "Aha!  It's Apache that's causing the problem and it doesn't even appear that my settings in php.ini have any effect."

 

I then changed Apache's Timeout from 10 to 120.

 

Two runs of the script were cut short between 37 and 40s of execution time, each using about 9.5MB of memory.  The third was able to finish in 37s of execution time using 1.08MB of memory.

 

I then changed PHP's max_execution_time from 10 to 120.

 

The script then ran successfully 3 times, each time taking between 36 and 40s of execution time and 2 of them using 9.28MB and 1 of them using 1.06MB.

 

So now I'm really confused.  On the way down, modifying php.ini didn't seem to have any effect.  But on the way up, it seemed to be the setting in php.ini that made the difference, but only after I had made the change in Apache.

 

Here is a log of my tests.  The ones that finished have the text end _EndDocument() at the end of the line.

[pre]

Time: 30.93 Mem: 0.51MB Group: APPL

Time: 30.87 Mem: 2.68MB Group: STRU

Time: 31.43 Mem: 6.46MB Group: ALLW

Time: 30.00 Mem: 0.58MB Group: PLUM

Time: 31.66 Mem: 2.69MB Group: APPL

 

CHANGE PHP MAX_EXECUTION_TIME FROM 30 -> 10

 

Time: 30.85 Mem: 1.38MB Group: SOLID

Time: 31.50 Mem: 1.36MB Group: ALLW

Time: 31.66 Mem: 0.75MB Group: WIND

 

CHANGE PHP MEMORY_LIMIT FROM 8M -> 1M

 

Time: 31.01 Mem: 9.49MB Group: GRA3CM

Time: 30.98 Mem: 1.25MB Group: APPL

Time: 30.68 Mem: 1.29MB Group: PLUMFX

 

CHANGE APACHE TIMEOUT FROM 30 -> 10

 

Time: 11.20 Mem: 6.14MB Group: LAMI

Time: 10.76 Mem: 9.15MB Group: GAR

 

CHANGE APACHE TIMEOUT FROM 10 -> 120

 

Time: 37.92 Mem: 9.59MB Group: PLUMFX

Time: 39.83 Mem: 9.56MB Group: LOWV

Time: 37.43 Mem: 1.08MB end _EndDocument()

 

CHANGE PHP MAX_EXECUTION_TIME FROM 10 -> 120

 

Time: 37.95 Mem: 9.28MB end _EndDocument()

Time: 36.13 Mem: 9.28MB end _EndDocument()

Time: 39.18 Mem: 1.06MB end _EndDocument()

 

 

### GOING BACK TO CTI'S WITH CURRENT SETTINGS

### PHP MAX_EXECUTION_TIME 120

### PHP MEMORY_LIMIT 1MB

### APACHE TIMEOUT 120

 

Time: 79.07 Mem: 22.97MB end _EndDocument()

[/pre]

Think of it this way.

 

If php timeout is set to 30 seconds and apaches is set to 120 seconds. PHP will timeout before apache correct?

 

On the other side if Apache timeout is set to 10 seconds and php is set to 30, apache will timeout before php, right?

 

So if apache is set to 120 seconds and php is set to 120 seconds, they will both time out at the same time.

 

But apache overrides PHP as it is the webserver, php is only allowed to run longer if apache let's it.

 

Make sense?

Yes, it does.

 

What doesn't make sense is if the PHP timeout is 10s and the Apache timeout is 30s that the script records an execution time of 30s.

 

And if the Apache timeout is 120s and the PHP timeout is 30s, how come the script times out at almost 40s?  There aren't any system or shell commands that I'm aware of in this script so all execution time should be spent by the PHP interpretor.

No.  The PDFs are generated with PDFLib and the script performs the following operations:

 

1) Gather data from MySQL

2) Open disk files (images to place in the PDF and other PDFs to import into final PDF)

3) Loop over data from step #1 and create catalog

4) Set headers and dump PDF buffer as output

 

In order to gather data from my tests I do some file logging as well.

 

I suppose the time spent interacting with MySQL and the disk could be the difference.

 

I should also note that get_memory_usage is not defined on my implementation so I'm using a custom one taken from the PHP documentation's user comments.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.