在 CRON 作业中使用时,stream_socket_client() 失败
我有一个脚本在浏览器中运行良好,但是在通过 CRON 运行时失败。
具体来说,该脚本使用 stream_socket_client()
创建安全套接字,但是尽管我在浏览器中运行时运行良好,但 CRON 端失败并出现以下错误:
PHP 警告:stream_socket_client():无法在第 18 行 /var/www/vhosts/tweetheartsapp.com/httpdocs/API/testSend.php 中启用加密 PHP 警告:stream_socket_client():无法连接到 /var/www/vhosts/tweetheartsapp.com/httpdocs/API/testSend.php 中的 ssl://gateway.sandbox.push.apple.com:2195 (未知错误)第 18 行
我使用以下命令来运行 CRON:
0-59 * * * * php -q httpdocs/API/testSend.php
通过 CRON 出现问题有什么原因吗?谁能给我一些关于如何在 CRON 中运行它的建议?
I have a script that runs fine in the browser, however fails when run through CRON.
Specifically, the script is using stream_socket_client()
to create a secure socket, however despite running fine when I run through the browser, the CRON side fails with the following errors:
PHP Warning: stream_socket_client(): Failed to enable crypto in /var/www/vhosts/tweetheartsapp.com/httpdocs/API/testSend.php on line 18
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /var/www/vhosts/tweetheartsapp.com/httpdocs/API/testSend.php on line 18
I am using the following command to run the CRON:
0-59 * * * * php -q httpdocs/API/testSend.php
Is there any reason for the problem via CRON? Can anyone give me any advice on how I can run this in CRON?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您从命令行运行该文件,可能会尝试提供 ck.pem 文件的完整路径,
请更改该行:
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');< /code>
到
stream_context_set_option($ctx, 'ssl', 'local_cert', '/path/to/your/file/ck.pem');
为我工作
if you running the file from the command line maybe try to give the full path to the ck.pem file
change the line :
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
to
stream_context_set_option($ctx, 'ssl', 'local_cert', '/path/to/your/file/ck.pem');
work for me
我更改了两件事来解决这个问题:
关闭 Plesk for PHP 中的安全模式。
将我的 cron 命令稍微修改为:
Two things I have changed which resolved this for me:
Turned off safe mode in Plesk for PHP.
Slightly altered my cron command to:
我遇到了同样的问题,发现通过从 cron 的同一目录运行 php 与从命令行运行 php 是有效的。 cron 条目如下所示:
I was having the same problem and found that by running php from the same directory from cron as from the command line that it worked. That is the cron entry would look like: