Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:36:27+00:00 2026-05-15T14:36:27+00:00

I primarily work in PHP and prefer to do so since there seem to

  • 0

I primarily work in PHP and prefer to do so since there seem to be more jobs in this language, at least in my area (and I’m still fairly new to it so I want to continue to learn the language better).. but for some things I want to do I need to use the WWW Mechanize library that doesn’t work with PHP but does with Ruby (yes I know PHP has some alternatives but I have tried them and they don’t work for me so I need to do this), so I’d like to write most of my app in PHP and then just call Ruby when I need to use this library, then pass the info back to PHP, yes I know this would be “slow” but thats not an issue in this case as this isn’t a public web app, its just for business use..

I’m wondering what the best way would be to pass info between the 2 languages.. I have thought of using http POST (like with Curl in PHP) to do this but not sure if this is the most efficient way any.. any info is appreciated, thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:36:28+00:00Added an answer on May 15, 2026 at 2:36 pm

    There are two different ways that I would do this:

    \1. In ruby, set up a non-HTTP server that only listens on ‘::’ (or 127.0.0.1 if you don’t like ipv6). Then, every time your PHP script needs to do something, it can connect to the server and pass data to it. This would be the fastest solution because the ruby script doesn’t need to start up every time PHP needs to do something.

    Example Ruby:

    require 'mechanize'
    require 'socket'
    
    def do_mechanize_stuff(command, *args)
      case command
      when 'search_google'
        # search google with args.join(' ')
      when 'answer_questions_on_stackoverflow'
        # answer questions on stackoverflow
        # with mechanize
      end
      'the result to pass to PHP'
    end
    
    srv = TCPServer.new '::', 3000
    
    loop do
      Thread.new(srv.accept) do |sock|
        sock.write(
          do_mechanize_stuff *sock.gets.split(' ')
        )
        sock.close
      end
    end
    

    Example Ruby client: (you will need to translate this to PHP)

    require 'socket'
    
    # This is a script that searches google
    # and writes the results to stdout.
    
    s = TCPSocket.new 'localhost', 3000
    
    s.puts 'search_google how to use a keyboard'
    
    until (r = s.gets).nil?
      print r # a search result.
    end
    

    You could use process watching tools like http://god.rubyforge.org/ to keep the server running.

    \2. Make the ruby script a command line utility, and use exec in PHP to call it.

    An example command line script:

    require 'mechanize'
    
    def do_mechanize_stuff(command, *args)
      # ... from previous example
    end
    
    do_mechanize_stuff ARGV.shift, ARGV
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.