Discussion:
[Symfony2] How to set the execution time limit of a controller including time spent on streams, db queries…etc?
Jarrett Croll
2012-08-28 04:06:51 UTC
Permalink
I have a controller that is executing multiple cURL requests to third party
API's and updating a database with the results (it's using the Guzzle http
client library <http://guzzlephp.org/> if that helps). I would like to set
the time limit that the script can execute dynamically in the application
(not system wide in php.ini). The problem is thatset_time_limit() has the
following limitations <http://php.net/manual/en/function.set-time-limit.php>
:

The set_time_limit() function and the configuration directive
max_execution_time only affect the execution time of the script itself. Any
time spent on activity that happens outside the execution of the script
such as system calls using system(), stream operations, database queries,
etc. is not included when determining the maximum time that the script has
been running.

For a controller executing hundreds or thousands of cURL requests the
differences between the script execution time and the *actual* execution
time adds up fast. I can get the connection time of the cURL request by
using curl_getinfo($ch, CURLINFO_TOTAL_TIME) so I might just do something
with this but then I noticed the profiler toolbar section called "Timeline"
is producing accurate results of how long the controller took to execute.
Is there some way I can access the profiler's measure of execution time?
Would it also be available in the production environment?

Is there some best practice for limiting the execution time of a Symfony2
controller including all streams and database calls?
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Franco Fallica
2012-08-28 09:05:36 UTC
Permalink
Some ideas. none of them tested.

1. You could use a command and a cronjob for that. no time limit on the cli.
something like get the request via http, store it somewhere, send
redirect response.
later the command picks up on that request does whater ever is needed,
and somewhere stores its progress.
redirect url polls status of the command.
if command finished redirect to the result

2. gradually increase time limit. (if that works)
$start = time();
$limit = 10 000;
set_time_limit($limit)
for () {


if (time() - $start > $limit - $someTreshhold) {
set_time_limit($limit *2);
$limit += $limit;
}
}
Post by Jarrett Croll
I have a controller that is executing multiple cURL requests to third party
API's and updating a database with the results (it's using the Guzzle http
client library if that helps). I would like to set the time limit that the
script can execute dynamically in the application (not system wide in
The set_time_limit() function and the configuration directive
max_execution_time only affect the execution time of the script itself. Any
time spent on activity that happens outside the execution of the script such
as system calls using system(), stream operations, database queries, etc. is
not included when determining the maximum time that the script has been
running.
For a controller executing hundreds or thousands of cURL requests the
differences between the script execution time and the actual execution time
adds up fast. I can get the connection time of the cURL request by using
curl_getinfo($ch, CURLINFO_TOTAL_TIME) so I might just do something with
this but then I noticed the profiler toolbar section called "Timeline" is
producing accurate results of how long the controller took to execute. Is
there some way I can access the profiler's measure of execution time? Would
it also be available in the production environment?
Is there some best practice for limiting the execution time of a Symfony2
controller including all streams and database calls?
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
--
--getunik ag-------------------------------------------
franco fallica franco.fallica-eQnHk2vpF/***@public.gmane.org
hardturmstrasse 101 fon: +41 (0)44 388 55 88
ch-8005 zuerich fax: +41 (0)44 388 55 89

--new getunik product-------------------------
Fundraising via SMS! Donations via SMS are fast, convenient and low priced!
www.getunik.com/smsspenden (in german)

we make the web a better place - www.getunik.com

*****************************************************************
think before you print - for the sake of nature
*****************************************************************
Jarrett Croll
2012-08-29 17:29:29 UTC
Permalink
Hi Franco,

Thanks for the reply. Unfortunately I don't follow what you are getting at
in suggestion #1.
Post by Franco Fallica
Some ideas. none of them tested.
1. You could use a command and a cronjob for that. no time limit on the cli.
something like get the request via http, store it somewhere, send
redirect response.
later the command picks up on that request does whater ever is needed,
and somewhere stores its progress.
redirect url polls status of the command.
if command finished redirect to the result
2. gradually increase time limit. (if that works)
$start = time();
$limit = 10 000;
set_time_limit($limit)
for () {
if (time() - $start > $limit - $someTreshhold) {
set_time_limit($limit *2);
$limit += $limit;
}
}
Post by Jarrett Croll
I have a controller that is executing multiple cURL requests to third
party
Post by Jarrett Croll
API's and updating a database with the results (it's using the Guzzle
http
Post by Jarrett Croll
client library if that helps). I would like to set the time limit that
the
Post by Jarrett Croll
script can execute dynamically in the application (not system wide in
php.ini). The problem is thatset_time_limit() has the following
The set_time_limit() function and the configuration directive
max_execution_time only affect the execution time of the script itself.
Any
Post by Jarrett Croll
time spent on activity that happens outside the execution of the script
such
Post by Jarrett Croll
as system calls using system(), stream operations, database queries,
etc. is
Post by Jarrett Croll
not included when determining the maximum time that the script has been
running.
For a controller executing hundreds or thousands of cURL requests the
differences between the script execution time and the actual execution
time
Post by Jarrett Croll
adds up fast. I can get the connection time of the cURL request by using
curl_getinfo($ch, CURLINFO_TOTAL_TIME) so I might just do something with
this but then I noticed the profiler toolbar section called "Timeline"
is
Post by Jarrett Croll
producing accurate results of how long the controller took to execute.
Is
Post by Jarrett Croll
there some way I can access the profiler's measure of execution time?
Would
Post by Jarrett Croll
it also be available in the production environment?
Is there some best practice for limiting the execution time of a
Symfony2
Post by Jarrett Croll
controller including all streams and database calls?
--
If you want to report a vulnerability issue on symfony, please send it
to
Post by Jarrett Croll
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
--
--getunik ag-------------------------------------------
hardturmstrasse 101 fon: +41 (0)44 388 55 88
ch-8005 zuerich fax: +41 (0)44 388 55 89
--new getunik product-------------------------
Fundraising via SMS! Donations via SMS are fast, convenient and low priced!
www.getunik.com/smsspenden (in german)
we make the web a better place - www.getunik.com
*****************************************************************
think before you print - for the sake of nature
*****************************************************************
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "Symfony2" group.
To post to this group, send email to symfony2-/***@public.gmane.org
To unsubscribe from this group, send email to
symfony2+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/symfony2?hl=en
Loading...