dqo88037 2014-09-05 10:48
浏览 129
已采纳

为什么stream_context_set_option的文件路径是搞乱的?

I have some PHP scripts in the following directory structure.

ROOT  
---COMMON  
------(Login.php)  
---APPSERVICE  
------(NotificationService.php)  
------NOTIFICATION_CERTIFICATES  
---------(ck.pem)

In NotificationService.php, I have the following line in my "notifyUser()" function:

stream_context_set_option($ctx, 'ssl', 'local_cert', **'NOTIFICATION_CERTIFICATES/ck.pem'**);

However, when I include NotificationService.php in my Login.php script and try to call notifyUser(), it gives me this error:

stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in [my file path]

However, if I call notifyUser() from a script in the same directory as NotificationService.php, there is no error. Why does the bolded line above seem to be affected by the script calling the function, rather than the location of the script that the function is defined in?

  • 写回答

1条回答 默认 最新

  • duanpuchun5275 2014-09-05 11:19
    关注

    Relative paths are resolved based on the include_path setting; this typically includes the current working directory that's established at the start of each request.

    If you want to make sure the path is always taken relative to the current script that's being run:

    // NotificationService.php
    
    $cert = __DIR__ . '/NOTIFICATION_CERTIFICATES/ck.pem';
    stream_context_set_option($ctx, 'ssl', 'local_cert', $cert);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?