C program and PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Chivers

    #1

    C program and PHP

    Hi,

    I have written this function in a C program, using Visual Studio. The
    PHP script executes fine, but the output is not displayed. I have
    been racking my brains for hours trying to figure this one out. The
    output from the php program should print to a file called 'out.txt'.
    The file is successfully created, but with no content. I am pretty
    sure it's the way PHP returns the results. Does anyone have any
    ideas? Any help would be most appreciated.

    int passCode(void)
    {
    FILE *phpFile, *out;
    size_t len;
    char buffer[1000];

    phpFile = popen("php -f testing1.php", "r");
    if (phpFile)
    {
    out = fopen("out.txt" , "w");
    len = fread(buffer, 1, sizeof(buffer), phpFile);
    fprintf(out, buffer);
    fclose(out);

    pclose(phpFile) ;

    return 1;
    }
    else
    {
    return 0;
    }
    }
  • Daniel Tryba

    #2
    Re: C program and PHP

    Ben Chivers <ben.chivers53@ ntlworld.com> wrote:[color=blue]
    > The output from the php program should print to a file called 'out.txt'.
    > The file is successfully created, but with no content. I am pretty
    > sure it's the way PHP returns the results. Does anyone have any
    > ideas? Any help would be most appreciated.[/color]

    Sounds like buffering is on in php. No output till you terminate the
    popen. See flush and Output Control in the reference.

    But why are you using php/C in this horrible way? It might be much
    nicer/easier to give php a commandline argument which contains the file
    to write to, system() the thing and when system return check if there is
    any useful output in the file.

    --

    Daniel Tryba

    Comment

    Working...