dongxian7489 2010-07-19 17:52
浏览 42
已采纳

来自SWIG生成的PHP扩展的stdout

I have the following C++ function:

void foo() {
    std::cout << "bar" << std::endl;
}

I'm porting this to PHP via SWIG. Everything compiles fine and the extension loads properly. I'm able to call foo() from PHP, but I only see the bar output if I run the PHP script from the command line.

$ php script.php
bar

If I load the script in the browser, nothing appears. Why does it not show bar in this case?

  • 写回答

1条回答 默认 最新

  • duangu1878 2010-07-27 00:39
    关注

    You can't print to stdout directly. This will of course only work if you're using the CLI SAPI. Use php_printf or any of these:

    //Calls php_output_write
    #define PHPWRITE(str, str_len)
    //Calls php_output_write_unbuffered
    #define PHPWRITE_H(str, str_len)
    //Idem:
    #define PUTC(c)
    #define PUTC_H(c)
    #define PUTS(str)
    #define PUTS_H(str)
    int php_write(void *buf, uint size TSRMLS_DC);
    int php_printf(const char *format, ...);
    int php_output_write(const char *str, size_t len TSRMLS_DC);
    int php_output_write_unbuffered(const char *str, size_t len TSRMLS_DC);
    //see the rest of main/output.c
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解