質問

I created shared library client.so. When I execute it main() function get executed which reads string from user and calls function ch=foo(buffer);.

Main.cpp is here:

#include<stdio.h>
#include "foo.h"

    int main()
    {
        char buffer[1024];
        char *ch;
        printf("Client : \n");
        printf("Enter sentence to send to the server (press enter)\n");
        fgets(buffer, 1024, stdin);
        ch=foo(buffer);

        return 0;
    }

Using exec function we can execute c program. But in php script if I do it for this I won't have option to read string from user.

I want that user can enter the string in browser itself and I pass that string to main function(probably using argv,argc- but I dont know how to do this). Then main function should proceed as usual calling foo(buffer) and so on.

foo(buffer) will return array which is stored in char* ch I want to receive in php script.

I have two option: 1] Reading string in text box from user and passing it to shared library file which has main() function. Which get executed and return "ch" in php script 2] Executing shared library file (as we do in terminal ./client) and giving string input at run time and getting entire program run. But I dont know this is possible or not. #include #include "foo.h"

    int main()
    {
        char buffer[1024];
        char *ch;
        printf("Client : \n");
        printf("Enter sentence to send to the server (press enter)\n");
        fgets(buffer, 1024, stdin);
        ch=foo(buffer);

        return 0;
    }

can anyone give me some suggestion for how this could be achieved!

役に立ちましたか?

解決

After setting the permission execute in following manner will solve the problem:

$a=exec('/home/technoworld/Videos/LinSocket/client "critic good"'); 

No need to give ./client just like I was making mistake!

client is the executable file that I wanted to execute and "critic good" is argument to be passed!

他のヒント

You can't do this so simple !

  1. you have to decide, if you really would like "exec" screw up your webserver
  2. you have to code your external helper tool as "non-blocking" application, this means: no CLI input things. This can be done, if you "input", and "output" your argument/parameter strings directly to the "non-blocking" application.
  3. you have to secure the webserver, and your wrapper tool, with the right permissions.
  4. you have to implement a timeout (or you have many zombie pid's)
  5. you have to code your application "thread" safe (webserver have to start multiple instances of your application, which generates only one session for each request (from logged in users).
  6. you have to test your application about volunteers (buffer overflows, ,,,)

If you would go in the right direction, you code a application, that is speciallized for your webserver (apache). This implies:

  1. wrting your application without UB.
  2. changing your webserver (apache) configuration: add directory securities, add application handler, that can handle then your files per .extension, or used with CGI interface.
  3. this implies, that you have a stable, fast running system with much memory as the home pc.

In other words: you should not use your application in this moment of development in productive systems.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top