Hi, I''ve got a little little check stock php script that uses the ODBTP php extension. Is there anyway to access it in a similar way to render(:partial => ""). So something like: render("http://www.remote.com/stock.php?part=PART")
On 10/26/05, James Earl <james-DkjEhSRHeDJAFePFGvp55w@public.gmane.org> wrote:> Hi, > > I''ve got a little little check stock php script that uses the ODBTP > php extension. Is there anyway to access it in a similar way to > render(:partial => ""). > > So something like: > > render("http://www.remote.com/stock.php?part=PART")Sure, you can use open_uri for that. I''d be sure to use some kind of fragment caching at least.
On 10/26/05, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10/26/05, James Earl <james-DkjEhSRHeDJAFePFGvp55w@public.gmane.org> wrote: > > Hi, > > > > I''ve got a little little check stock php script that uses the ODBTP > > php extension. Is there anyway to access it in a similar way to > > render(:partial => ""). > > > > So something like: > > > > render("http://www.remote.com/stock.php?part=PART") > > Sure, you can use open_uri for that. I''d be sure to use some kind of > fragment caching at least.Thanks, that worked!
On Oct 26, 2005, at 2:26 PM, James Earl wrote:> Hi, > > I''ve got a little little check stock php script that uses the ODBTP > php extension. Is there anyway to access it in a similar way to > render(:partial => ""). > > So something like: > > render("http://www.remote.com/stock.php?part=PART") > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >I have to do the same things for a few parts of a site I am building. Beware pulling remote pages from other servers. When that other server gets slow or goes off line you can get funny behavior in your rails app. Here is a method in my model that tries a few times to fetch a remote page and then fails after a predetermined amount of tries: require ''net/http'' require ''uri'' class Page < ActiveRecord::Base def self.fetch_php(url, limit=5) data = '''' begin data = Net::HTTP.get_response(URI.parse(url)) rescue limit -= 1 limit > 0 ? retry : raise end data.body end end -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
On 10/26/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote:> > On Oct 26, 2005, at 2:26 PM, James Earl wrote: > > > Hi, > > > > I''ve got a little little check stock php script that uses the ODBTP > > php extension. Is there anyway to access it in a similar way to > > render(:partial => ""). > > > > So something like: > > > > render("http://www.remote.com/stock.php?part=PART") > > I have to do the same things for a few parts of a site I am building. > Beware pulling remote pages from other servers. When that other > server gets slow or goes off line you can get funny behavior in your > rails app. Here is a method in my model that tries a few times to > fetch a remote page and then fails after a predetermined amount of > tries: > > > require ''net/http'' > require ''uri'' > > class Page < ActiveRecord::Base > > def self.fetch_php(url, limit=5) > data = '''' > begin > data = Net::HTTP.get_response(URI.parse(url)) > rescue > limit -= 1 > limit > 0 ? retry : raise > end > data.body > end > > endThanks Ezra, Is there any advantages/disadvantages to using open-uri vs. Net::HTTP?
On Oct 26, 2005, at 5:29 PM, James Earl wrote:> On 10/26/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote: > >> >> On Oct 26, 2005, at 2:26 PM, James Earl wrote: >> >> >>> Hi, >>> >>> I''ve got a little little check stock php script that uses the ODBTP >>> php extension. Is there anyway to access it in a similar way to >>> render(:partial => ""). >>> >>> So something like: >>> >>> render("http://www.remote.com/stock.php?part=PART") >>> >> >> I have to do the same things for a few parts of a site I am building. >> Beware pulling remote pages from other servers. When that other >> server gets slow or goes off line you can get funny behavior in your >> rails app. Here is a method in my model that tries a few times to >> fetch a remote page and then fails after a predetermined amount of >> tries: >> >> >> require ''net/http'' >> require ''uri'' >> >> class Page < ActiveRecord::Base >> >> def self.fetch_php(url, limit=5) >> data = '''' >> begin >> data = Net::HTTP.get_response(URI.parse(url)) >> rescue >> limit -= 1 >> limit > 0 ? retry : raise >> end >> data.body >> end >> >> end >> > > Thanks Ezra, > > Is there any advantages/disadvantages to using open-uri vs. Net::HTTP? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >I believe that open-uri uses net/http or something very similar to do http requests. There is no speed difference with either. Open-uri is a bit simpler interface which is cool. Either one will work fine for this use. HTH- -Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org 509-577-7732
Thanks, Is it possible to run a PHP script directly from within Rails? Say you had a PHP script in the public/ directory. I know you can call it directly such as http://localhost:3000/stock.php, but is it basically too late once Rails has taken control to parse the PHP script? On 10/26/05, Ezra Zygmuntowicz <ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org> wrote:> > On Oct 26, 2005, at 5:29 PM, James Earl wrote: > > > On 10/26/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote: > > > >> > >> On Oct 26, 2005, at 2:26 PM, James Earl wrote: > >> > >> > >>> Hi, > >>> > >>> I''ve got a little little check stock php script that uses the ODBTP > >>> php extension. Is there anyway to access it in a similar way to > >>> render(:partial => ""). > >>> > >>> So something like: > >>> > >>> render("http://www.remote.com/stock.php?part=PART") > >>> > >> > >> I have to do the same things for a few parts of a site I am building. > >> Beware pulling remote pages from other servers. When that other > >> server gets slow or goes off line you can get funny behavior in your > >> rails app. Here is a method in my model that tries a few times to > >> fetch a remote page and then fails after a predetermined amount of > >> tries: > >> > >> > >> require ''net/http'' > >> require ''uri'' > >> > >> class Page < ActiveRecord::Base > >> > >> def self.fetch_php(url, limit=5) > >> data = '''' > >> begin > >> data = Net::HTTP.get_response(URI.parse(url)) > >> rescue > >> limit -= 1 > >> limit > 0 ? retry : raise > >> end > >> data.body > >> end > >> > >> end > >> > > > > Thanks Ezra, > > > > Is there any advantages/disadvantages to using open-uri vs. Net::HTTP? > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > I believe that open-uri uses net/http or something very similar to do > http requests. There is no speed difference with either. Open-uri is > a bit simpler interface which is cool. Either one will work fine for > this use. > > HTH- > > -Ezra Zygmuntowicz > WebMaster > Yakima Herald-Republic Newspaper > ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org > 509-577-7732 > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi, On my apache setup, I have PHP files in public/ that work fine. I doubt webrick (as implied by :3000) has a PHP interpreter built in, however. -Matt B On Thu, 2005-10-27 at 08:34 -0600, James Earl wrote:> Thanks, > > Is it possible to run a PHP script directly from within Rails? Say > you had a PHP script in the public/ directory. I know you can call it > directly such as http://localhost:3000/stock.php, but is it basically > too late once Rails has taken control to parse the PHP script? > > > On 10/26/05, Ezra Zygmuntowicz <ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org> wrote: > > > > On Oct 26, 2005, at 5:29 PM, James Earl wrote: > > > > > On 10/26/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote: > > > > > >> > > >> On Oct 26, 2005, at 2:26 PM, James Earl wrote: > > >> > > >> > > >>> Hi, > > >>> > > >>> I''ve got a little little check stock php script that uses the ODBTP > > >>> php extension. Is there anyway to access it in a similar way to > > >>> render(:partial => ""). > > >>> > > >>> So something like: > > >>> > > >>> render("http://www.remote.com/stock.php?part=PART") > > >>> > > >> > > >> I have to do the same things for a few parts of a site I am building. > > >> Beware pulling remote pages from other servers. When that other > > >> server gets slow or goes off line you can get funny behavior in your > > >> rails app. Here is a method in my model that tries a few times to > > >> fetch a remote page and then fails after a predetermined amount of > > >> tries: > > >> > > >> > > >> require ''net/http'' > > >> require ''uri'' > > >> > > >> class Page < ActiveRecord::Base > > >> > > >> def self.fetch_php(url, limit=5) > > >> data = '''' > > >> begin > > >> data = Net::HTTP.get_response(URI.parse(url)) > > >> rescue > > >> limit -= 1 > > >> limit > 0 ? retry : raise > > >> end > > >> data.body > > >> end > > >> > > >> end > > >> > > > > > > Thanks Ezra, > > > > > > Is there any advantages/disadvantages to using open-uri vs. Net::HTTP? > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > I believe that open-uri uses net/http or something very similar to do > > http requests. There is no speed difference with either. Open-uri is > > a bit simpler interface which is cool. Either one will work fine for > > this use. > > > > HTH- > > > > -Ezra Zygmuntowicz > > WebMaster > > Yakima Herald-Republic Newspaper > > ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org > > 509-577-7732 > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Sorry, I should''ve been more clear. I''m wondering if you could use something like render to include the parsed results of a PHP file in a Rails Controller or View. Eg. <%= render_this_old_php_script_parsed_of_course(''stock.php'') %> Something like PHP include... but instead, we''re include''ing a PHP script from a Rails app :) Even better... I should see what would be involved in getting Ruby bindings to ODBTP! On 10/27/05, Matthew Beale <mixonic-8rZIAEcCR/xWk0Htik3J/w@public.gmane.org> wrote:> Hi, > > On my apache setup, I have PHP files in public/ that work fine. I doubt > webrick (as implied by :3000) has a PHP interpreter built in, however. > > -Matt B > > On Thu, 2005-10-27 at 08:34 -0600, James Earl wrote: > > Thanks, > > > > Is it possible to run a PHP script directly from within Rails? Say > > you had a PHP script in the public/ directory. I know you can call it > > directly such as http://localhost:3000/stock.php, but is it basically > > too late once Rails has taken control to parse the PHP script? > > > > > > On 10/26/05, Ezra Zygmuntowicz <ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org> wrote: > > > > > > On Oct 26, 2005, at 5:29 PM, James Earl wrote: > > > > > > > On 10/26/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote: > > > > > > > >> > > > >> On Oct 26, 2005, at 2:26 PM, James Earl wrote: > > > >> > > > >> > > > >>> Hi, > > > >>> > > > >>> I''ve got a little little check stock php script that uses the ODBTP > > > >>> php extension. Is there anyway to access it in a similar way to > > > >>> render(:partial => ""). > > > >>> > > > >>> So something like: > > > >>> > > > >>> render("http://www.remote.com/stock.php?part=PART") > > > >>> > > > >> > > > >> I have to do the same things for a few parts of a site I am > building. > > > >> Beware pulling remote pages from other servers. When that other > > > >> server gets slow or goes off line you can get funny behavior in your > > > >> rails app. Here is a method in my model that tries a few times to > > > >> fetch a remote page and then fails after a predetermined amount of > > > >> tries: > > > >> > > > >> > > > >> require ''net/http'' > > > >> require ''uri'' > > > >> > > > >> class Page < ActiveRecord::Base > > > >> > > > >> def self.fetch_php(url, limit=5) > > > >> data = '''' > > > >> begin > > > >> data = Net::HTTP.get_response(URI.parse(url)) > > > >> rescue > > > >> limit -= 1 > > > >> limit > 0 ? retry : raise > > > >> end > > > >> data.body > > > >> end > > > >> > > > >> end > > > >> > > > > > > > > Thanks Ezra, > > > > > > > > Is there any advantages/disadvantages to using open-uri vs. > Net::HTTP? > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > I believe that open-uri uses net/http or something very similar to do > > > http requests. There is no speed difference with either. Open-uri is > > > a bit simpler interface which is cool. Either one will work fine for > > > this use. > > > > > > HTH- > > > > > > -Ezra Zygmuntowicz > > > WebMaster > > > Yakima Herald-Republic Newspaper > > > ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org > > > 509-577-7732 > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Yeah there is no problem serving php or cgi or even just plain html or shtml files from your public directory. It just depends on what webserver you are using. If you are using apache and php is set up for any other sites on your apache install then just drop your .php pages right inside of public or and subdirectory of public. If you are running lighttpd/fcgi then you need to install the php cli version either php-cgi or even better php-fcgi. Then you add this to your fastcgi.server part of your lighttpd.conf: fastcgi.server = ( ".fcgi" => ( "yhr_app" => ( "socket" => "/tmp/yhr_app.socket", "bin-environment" => ( "RAILS_ENV" => "production" ), "bin-path" => "/Users/admin/Sites/yhr/public/dispatch.fcgi", ) ), ".php" => ( "localhost" => ( "socket" => "/tmp/php-fcgi.socket", "bin-path" => "/usr/bin/php-fcgi", "bin-environment" => ( "PHP_FCGI_CHILDREN" => "4", "PHP_FCGI_MAX_REQUESTS" => "2000" ) ) ) ) And include .php files can be indexes: server.indexfiles = ( "dispatch.fcgi", "index.html", "index.php" ) Then you are good to go. Through a test.php file with the phpinfo(); command in it and make sure it works. Cheers- -Ezra On Oct 27, 2005, at 7:34 AM, James Earl wrote:> Thanks, > > Is it possible to run a PHP script directly from within Rails? Say > you had a PHP script in the public/ directory. I know you can call it > directly such as http://localhost:3000/stock.php, but is it basically > too late once Rails has taken control to parse the PHP script? > > > On 10/26/05, Ezra Zygmuntowicz <ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org> wrote: > >> >> On Oct 26, 2005, at 5:29 PM, James Earl wrote: >> >> >>> On 10/26/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote: >>> >>> >>>> >>>> On Oct 26, 2005, at 2:26 PM, James Earl wrote: >>>> >>>> >>>> >>>>> Hi, >>>>> >>>>> I''ve got a little little check stock php script that uses the >>>>> ODBTP >>>>> php extension. Is there anyway to access it in a similar way to >>>>> render(:partial => ""). >>>>> >>>>> So something like: >>>>> >>>>> render("http://www.remote.com/stock.php?part=PART") >>>>> >>>>> >>>> >>>> I have to do the same things for a few parts of a site I am >>>> building. >>>> Beware pulling remote pages from other servers. When that other >>>> server gets slow or goes off line you can get funny behavior in >>>> your >>>> rails app. Here is a method in my model that tries a few times to >>>> fetch a remote page and then fails after a predetermined amount of >>>> tries: >>>> >>>> >>>> require ''net/http'' >>>> require ''uri'' >>>> >>>> class Page < ActiveRecord::Base >>>> >>>> def self.fetch_php(url, limit=5) >>>> data = '''' >>>> begin >>>> data = Net::HTTP.get_response(URI.parse(url)) >>>> rescue >>>> limit -= 1 >>>> limit > 0 ? retry : raise >>>> end >>>> data.body >>>> end >>>> >>>> end >>>> >>>> >>> >>> Thanks Ezra, >>> >>> Is there any advantages/disadvantages to using open-uri vs. >>> Net::HTTP? >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> >> >> I believe that open-uri uses net/http or something very similar to do >> http requests. There is no speed difference with either. Open-uri is >> a bit simpler interface which is cool. Either one will work fine for >> this use. >> >> HTH- >> >> -Ezra Zygmuntowicz >> WebMaster >> Yakima Herald-Republic Newspaper >> ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org >> 509-577-7732 >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
I think I should have read your post here a bit more completely. There is no way for rails to execute php scripts with just ruby. But you can either do like I showed with the fetch_pfp stuff or make sure you install the CLI version of php and then you can do something like this in your view: <%= system("/usr/bin/php-cgi /path/to/your/php/include.php") %> That will just shell out to the cli version of php and process the php script and print it in your view. IS that more like what you wanted? -Ezra On Oct 27, 2005, at 7:34 AM, James Earl wrote:> Thanks, > > Is it possible to run a PHP script directly from within Rails? Say > you had a PHP script in the public/ directory. I know you can call it > directly such as http://localhost:3000/stock.php, but is it basically > too late once Rails has taken control to parse the PHP script? > > > On 10/26/05, Ezra Zygmuntowicz <ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org> wrote: > >> >> On Oct 26, 2005, at 5:29 PM, James Earl wrote: >> >> >>> On 10/26/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote: >>> >>> >>>> >>>> On Oct 26, 2005, at 2:26 PM, James Earl wrote: >>>> >>>> >>>> >>>>> Hi, >>>>> >>>>> I''ve got a little little check stock php script that uses the >>>>> ODBTP >>>>> php extension. Is there anyway to access it in a similar way to >>>>> render(:partial => ""). >>>>> >>>>> So something like: >>>>> >>>>> render("http://www.remote.com/stock.php?part=PART") >>>>> >>>>> >>>> >>>> I have to do the same things for a few parts of a site I am >>>> building. >>>> Beware pulling remote pages from other servers. When that other >>>> server gets slow or goes off line you can get funny behavior in >>>> your >>>> rails app. Here is a method in my model that tries a few times to >>>> fetch a remote page and then fails after a predetermined amount of >>>> tries: >>>> >>>> >>>> require ''net/http'' >>>> require ''uri'' >>>> >>>> class Page < ActiveRecord::Base >>>> >>>> def self.fetch_php(url, limit=5) >>>> data = '''' >>>> begin >>>> data = Net::HTTP.get_response(URI.parse(url)) >>>> rescue >>>> limit -= 1 >>>> limit > 0 ? retry : raise >>>> end >>>> data.body >>>> end >>>> >>>> end >>>> >>>> >>> >>> Thanks Ezra, >>> >>> Is there any advantages/disadvantages to using open-uri vs. >>> Net::HTTP? >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> >> >> I believe that open-uri uses net/http or something very similar to do >> http requests. There is no speed difference with either. Open-uri is >> a bit simpler interface which is cool. Either one will work fine for >> this use. >> >> HTH- >> >> -Ezra Zygmuntowicz >> WebMaster >> Yakima Herald-Republic Newspaper >> ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org >> 509-577-7732 >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
On 10/27/05, Ezra Zygmuntowicz <ezra-SD1UcFUIF7QjH4SCZfkgnw@public.gmane.org> wrote:> I think I should have read your post here a bit more completely. > There is no way for rails to execute php scripts with just ruby. But > you can either do like I showed with the fetch_pfp stuff or make sure > you install the CLI version of php and then you can do something like > this in your view: > > <%= system("/usr/bin/php-cgi /path/to/your/php/include.php") %> > > That will just shell out to the cli version of php and process the > php script and print it in your view. IS that more like what you wanted?Yes, thanks! I think I''ll stick with your first Net::HTTP example though, that way I don''t have to install the CLI version of PHP. Thanks for your help! James