Thread: php to execute c++ programs

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    4

    php to execute c++ programs

    Currently I have PHP4 running on my localhost and I can execute programs that I've written (a simple program that will insert a dummy entry into a sqlite database).

    What I want to do is somehow initiate an event in a program (a daemon to be specific), (unlike previously executing a specific program).

    I have this board that needs to be pinged, and I am required that I do not run a separate program. I need to see how I can turn on like an interrupt, or perhaps a polling scheme to allow this, but I'm not sure how it can be done.

    Another solution would be to call a program, which will interface with the daemon... how would that work?

    Thanks in advance!

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, first you'll need to figure out how to interface with the daemon... it's not like there's a standard that says "All daemons must interface in this way: ___".

    >>I need to see how I can turn on like an interrupt, or perhaps a polling scheme to allow this
    As above: it's 100% up to the daemon how it chooses to interface with the user, assuming it does in the first place. Whether it polls on a file, or a socket, or who-knows-what, varies from daemon to daemon. Your best bet will be to read the daemon's man page (assuming it has one) and find out what mechanisms you have to work with.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    4
    well, i currently have this post button:

    <form method="POST" action="<?php exec("/root/armtest"); ?>">

    however in the end I want to be able to trigger a function within a c++ program (the daemon) that is written. I have no clue how to do this. any ideas?

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    are you the one who codes the daemon?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Real oldschool programmers aren't afraid to use goto

  6. #6
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    When you execute the program pass an argument to it and in the program, execute that function when the specified input is entered. Just a suggestion maybe I don't understand what you're asking.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
    Echo Mario F. above.
    If the answer is 'no', echo Hunter2 above.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by kdoggfunkstah
    well, i currently have this post button:

    <form method="POST" action="<?php exec("/root/armtest"); ?>">
    That probably doesn't do what you want it to do. (Learn PHP...) That will output "<form method="POST" action="">, and armtest will execute when the page is loaded, not when the button is pushed.
    You could do the following:
    Code:
    <?php
    if(isset($_POST['runprog'])) exec("/root/armtest");
    ?>
    <form method="POST" action="url/to/this/page.php">
    <input type="hidden" name="runprog" value="1" />
    <input type="submit" />
    </form>
    Quote Originally Posted by kdoggfunkstah
    however in the end I want to be able to trigger a function within a c++ program (the daemon) that is written. I have no clue how to do this. any ideas?
    How would you do it normally? Once you know that, do it the same way in your PHP code. This is much easier if you're the writer of the program.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by Cactus_Hugger
    Code:
    <input type="hidden" name="runprog" value="1" />
    <input type="submit" />
    Or simply
    Code:
    <input type="submit" name="runprog" value="Submit" />
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. php preg_match equivalent for c
    By pixsta in forum C++ Programming
    Replies: 7
    Last Post: 09-03-2005, 02:59 AM
  2. creating DLL's to allow people to execute MFC programs
    By Jamsan in forum Windows Programming
    Replies: 1
    Last Post: 03-03-2003, 02:03 AM
  3. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  4. Programs works one way, not another. VC++ 6.0 help.
    By Cheeze-It in forum Windows Programming
    Replies: 4
    Last Post: 12-10-2002, 10:29 PM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM