# Sharing Sessions between Rails & Php

**URL:** <https://www.ruby-forum.com/t/sharing-sessions-between-rails-php/127644>\
**Category:** Rails\
**Created:** [January 31, 2008, 1:28am UTC](https://www.ruby-forum.com/t/sharing-sessions-between-rails-php/127644 "2008-01-31T01:28:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [January 31, 2008, 1:28am UTC](https://www.ruby-forum.com/t/sharing-sessions-between-rails-php/127644/1 "2008-01-31T01:28:56Z")

</div>

Hey there everyone

Does anyone have any experience on this and if so could you please  
guide me in the right direction?

I have a rails app which is password protected using acts as  
authenticated  
I want to use php for the uploads section of the app for the following  
reasons:

1. Php does not have problems with blocking like rails on file uploads
2. Php/imagemagick is way less processor intensive than rails/rmagick
3. I m potentially going to uploading video and processing with ffmpeg  
and for the two reasons above php would probably be more sensible.

I want to be able to check if a user is logged from within my php app  
and this is how i am proposing to do it

1. Log in via rails site, browse to image page
2. grab the session id from rails and the user id and pass them to the  
php upload script. i am assuming rails will write a unique session  
identifyer file to /tmp ? or the same in the database  
for example the url for the php script might look something like this:

[http://media.mydomain.com/images/upload.php?session=2139adfskjhagfdkj&user\_id=12312](http://media.mydomain.com/images/upload.php?session=2139adfskjhagfdkj&user_id=12312)

1. from the php script check to see the user exists and the session  
exists for this user and do the image upload/processing
2. redirect to the rails page

when the user logs out/session expires obviously the php would throw  
an error and not work because the session would be deleted

Does anyone hae any experience with sharing sessions between rails and  
php???  
Is there any librarys for such?  
what would be a more secure way of doing this?

thanks Adam

---

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [January 31, 2008, 10:08am UTC](https://www.ruby-forum.com/t/sharing-sessions-between-rails-php/127644/2 "2008-01-31T10:08:54Z")

</div>

On 31 Jan 2008, at 01:28, Adam J. wrote:

> I have a rails app which is password protected using acts as  
> authenticated  
> I want to use php for the uploads section of the app for the following  
> reasons:
> 
> 1. Php does not have problems with blocking like rails on file uploads

If you’re really that worried about the blocking (which hasn’t been a  
problem for one of my apps at all, because it doesn’t block until  
AFTER the upload is finished and I immediately hand it over to  
backgroundrb), use Merb which allows you to use Rails sessions and  
ActiveRecord and is multithreaded.

> 1. Php/imagemagick is way less processor intensive than rails/rmagick

Use ImageScience if all you want to do is create thumbnails, or  
minimagick, which uses ImageMagick via the command line.

> 1. I m potentially going to uploading video and processing with ffmpeg  
> and for the two reasons above php would probably be more sensible.

That’s what I’m doing in one of the custom apps I created,  
backgroundrb handles that for me and it integrates better with Rails  
than PHP.

This whole single threaded nature of Rails has been blown so out of  
proportion that as soon as a beginning (or probably even more  
seasoned) Rails developer hears “file uploads”, loud alarms start  
ringing all over the place, everybody panics and starts running  
around like a chicken without a head. Don’t, just don’t. It’s just  
something you need to be aware of and use an elegant solution for,  
not something to sign a pact with an old devil for.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [January 31, 2008, 10:33am UTC](https://www.ruby-forum.com/t/sharing-sessions-between-rails-php/127644/3 "2008-01-31T10:33:03Z")

</div>

On 31/01/2008, at 10:08 PM, Peter De Berdt wrote:

> > uploads  
> > minimagick, which uses ImageMagick via the command line.  
> > proportion that as soon as a beginning (or probably even more
> 
> >

Cheers Peter. appreciate your advice  
I think i will run with merb for all uploads or investigate as you  
said handing the image processing of to another thread.  
I had also worked out how do do it in php just by grabbing the active  
session\_id from the cookie and the userid from a parameter and  
checking against the user database to see there had been activity in  
the last few mins (ie user was logged in)

Are you using rmovie or are you passing it straight to the command  
line for ffmpeg?

regards Adam

---

<div class="post-metadata">

**Author:** ![sideshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@sideshow](https://www.ruby-forum.com/u/sideshow)\
**Post date:** [January 31, 2008, 10:47am UTC](https://www.ruby-forum.com/t/sharing-sessions-between-rails-php/127644/4 "2008-01-31T10:47:49Z")

</div>

On 31 Jan 2008, at 10:32, Adam J. wrote:

> Cheers Peter. appreciate your advice  
> I think i will run with merb for all uploads or investigate as you  
> said handing the image processing of to another thread.  
> I had also worked out how do do it in php just by grabbing the  
> active session\_id from the cookie and the userid from a parameter  
> and checking against the user database to see there had been  
> activity in the last few mins (ie user was logged in)
> 
> Are you using rmovie or are you passing it straight to the command  
> line for ffmpeg?

I’m using a straight command line call, works fine for my needs.

Best regards

Peter De Berdt
