php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #57880 Capturing output via exp_loguser from within PHP / Apache
Submitted: 2007-10-17 16:30 UTC Modified: 2007-10-20 03:18 UTC
From: maport1 at uky dot edu Assigned:
Status: Closed Package: expect (PECL)
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: maport1 at uky dot edu
New email:
PHP Version: OS:

 

 [2007-10-17 16:30 UTC] maport1 at uky dot edu
Description:
------------
Is there a method so that the Expect library output (turned on via exp_loguser) is accessible to the calling script running with PHP as an Apache module?  For example, this would be used to display a telnet session trace when it has failed out.  In my testing, it appears that the output is sent to the php://stdout stream, and thus it is unavailable to the calling script within Apache.  I understand that exp_logfile can be set to redirect output to a file, but is it possible to somehow pass a flag so that the log is actually displayed in the php://output stream?  I would attempt this myself (as with the subpattern matching changes), but I don't understand enough of the underlying Zend streams model to join the output streams.

Reproduce code:
---------------
<?php
    ini_set("expect.loguser", 1);

    ob_start();

    print "Opening connection to localhost ...\n";
    $fp = fopen("expect://ssh 127.0.0.1", "r");

    . . . .

    fclose($fp);

    $trace = ob_get_contents();
?>

Expected result:
----------------
$trace contains the full output from Expect

Actual result:
--------------
$trace contains only output sent via the print and echo commands

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-17 17:30 UTC] maport1 at uky dot edu
Mark Frost and I created a patch that *appears* to work in the manner I was expecting.  It adds a fourth .ini boolean parameter, expect.logoutput, that passes the php://output stream to exp_logfile.  We would, however, appreciate a second eye checking for potential errors.

Here is the patch:

--- expect-0.2.3/expect.c       2006-07-05 10:51:56.000000000 -0400
+++ expect-0.2.4/expect.c       2007-10-17 17:19:40.000000000 -0400
@@ -82,7 +82,7 @@
        if (new_value_length > 0) {
                exp_logfile = fopen (new_value, "a");
                if (!exp_logfile) {
-                       php_error_docref (NULL TSRMLS_CC, E_ERROR, "could not open log file for writting");
+                       php_error_docref (NULL TSRMLS_CC, E_ERROR, "could not open log file for writing");
                        return FAILURE;
                }
        }
@@ -91,10 +91,27 @@
 /* }}} */
 
 
+/* {{{ PHP_INI_MH
+ *  */
+static PHP_INI_MH(OnSetExpectLogOutput)
+{
+       if (new_value) {
+               if (!strncasecmp("on", new_value, sizeof("on")) || atoi(new_value)) {
+                       php_stream *out = php_stream_open_wrapper("php://output", "w", 0, NULL);
+                       FILE * php_output;
+                       (void) php_stream_cast(out, PHP_STREAM_AS_STDIO, (void **) &php_output, REPORT_ERRORS);
+                       exp_logfile = php_output;
+               }
+       }
+}
+/* }}} */
+
+
 PHP_INI_BEGIN()
        PHP_INI_ENTRY("expect.timeout", "10", PHP_INI_ALL, OnSetExpectTimeout)
        PHP_INI_ENTRY_EX("expect.loguser", "1", PHP_INI_ALL, OnSetExpectLogUser, php_ini_boolean_displayer_cb)
        PHP_INI_ENTRY("expect.logfile", "", PHP_INI_ALL, OnSetExpectLogFile)
+       PHP_INI_ENTRY_EX("expect.logoutput", "0", PHP_INI_ALL, OnSetExpectLogOutput, php_ini_boolean_displayer_cb)
 PHP_INI_END()
 [2007-10-20 03:18 UTC] spektom at gmail dot com
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pecl.php.net/get/expect

Fixed in v.0.2.4

Use set_ini('expect.logfile', 'php://output') for re-directing expect output to output buffer mechanism.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 13:01:28 2025 UTC