# System call calls a PHP script

**URL:** <https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153>\
**Category:** Rails\
**Created:** [December 14, 2007, 1:14pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153 "2007-12-14T13:14:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 14, 2007, 1:14pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/1 "2007-12-14T13:14:35Z")

</div>

Hello,

I want to generate some PDFs from my Rails app.  
I use a PHP script to generate the PDF, and it works fine.

In my Rails controller, I just have an action that calls :  
`#{full_command}`  
where full\_command is something like “/usr/bin/php generate\_pdf.php”.

It just works fine.

Now I want to stress test a little my application.  
I use this simple ruby script to test my PDF generation :

#!/usr/bin/ruby  
10.times do  
`curl http://0.0.0.0:3000/contents/pdf`  
end

The result is that only 3 PDFs are generated.

If I use this ruby script :  
#!/usr/bin/ruby

10.times do  
`/usr/bin/php generate_pdf.php`  
end

Then the 10 PDFs are generated very quickly.

Does anyone have a clue about what I could do for the 10 PDFs being  
generated when called in my Rails controller?  
I can’t realize where the problem is …

Is this a Mongrel issue (I’m using Rails 2.0 with the Mongrel test  
environment)?  
Does I have to use something like BackgroundRB? (I’d prefer not to).

Thanks in advance for your lights.  
Best,  
Thomas.

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 14, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/2 "2007-12-14T13:24:01Z")

</div>

I would guess that this is related to the fact that you fire of 10  
requests to your webserver in absolutely no time(under 1ms?). I think  
not all your requests are being processed by the server. Try:  
#!/usr/bin/ruby  
10.times do  
Kernel.sleep(0.1) #in seconds  
`curl http://0.0.0.0:3000/contents/pdf`  
end

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 14, 2007, 1:42pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/3 "2007-12-14T13:42:14Z")

</div>

Thanks for your help.

On Dec 14, 2007 1:23 PM, harm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I would guess that this is related to the fact that you fire of 10  
> requests to your webserver in absolutely no time(under 1ms?). I think  
> not all your requests are being processed by the server.

in my development.log, I can see that the 10 requests are processed.

> Try:  
> #!/usr/bin/ruby  
> 10.times do  
> Kernel.sleep(0.1) #in seconds  
> `curl http://0.0.0.0:3000/contents/pdf`  
> end

I have to increase the sleep time to 0.8 secs in order to have the 10  
PDFs generated.  
So if 10 people request the PDF at the same time, they won’t have it  
generated. :-/

Any idea?

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 14, 2007, 1:52pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/4 "2007-12-14T13:52:15Z")

</div>

I’m using the Mongrel that ships with Rails 2.0.1, with the DEV  
environment.  
I’ve tried to put my `#{full_command}` in a BackgroundRB worker, but I  
get the same problem …

I’m a little bit stuck … :-/

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 15, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/5 "2007-12-15T20:32:35Z")

</div>

On Dec 14, 2007 6:21 PM, Thomas B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m using the Mongrel that ships with Rails 2.0.1, with the DEV environment.  
> I’ve tried to put my `#{full_command}` in a BackgroundRB worker, but I  
> get the same problem …
> 
> I’m a little bit stuck … :-/

Which version of bdrb? Can you paste the code of your worker?

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://gnufied.org](http://gnufied.org)

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 14, 2007, 1:46pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/6 "2007-12-14T13:46:21Z")

</div>

Not sure on what webserver you are testing on, but from your script I  
am guessing Webbrick. Which is really only for testing and not for  
production. When using Apache/Mongrel you will see vastly increased  
response times. And it is the response times you are concerned about.  
I dont think you PDF generation script is too slow.

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 17, 2007, 7:22am UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/7 "2007-12-17T07:22:55Z")

</div>

Thomas,

On Dec 16, 2007 8:43 PM, Thomas B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I downloaded the last version of bdrb from the SVN trunk.  
> My code in the worker was just a single line :  
> `#{full_command}` where full\_command looks like “/usr/bin/php generate\_pdf.php”

You need to specify full path to generate\_pdf.php, that will solve the  
problem.

> > > I’m a little bit stuck … :-/
> > 
> > >
> 
> >

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://gnufied.org](http://gnufied.org)

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [December 16, 2007, 4:14pm UTC](https://www.ruby-forum.com/t/system-call-calls-a-php-script/123153/8 "2007-12-16T16:14:01Z")

</div>

I downloaded the last version of bdrb from the SVN trunk.  
My code in the worker was just a single line :  
`#{full_command}` where full\_command looks like “/usr/bin/php  
generate\_pdf.php”
