在 CRON 作业中使用时,stream_socket_client() 失败

发布于 2024-09-19 01:16:33 字数 591 浏览 6 评论 0原文

我有一个脚本在浏览器中运行良好,但是在通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏雨凉 2024-09-26 01:16:35

如果您从命令行运行该文件,可能会尝试提供 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

潦草背影 2024-09-26 01:16:35

我更改了两件事来解决这个问题:

关闭 Plesk for PHP 中的安全模式。

将我的 cron 命令稍微修改为:

0-59 * * * * /usr/bin/php -q httpdocs/API/testSend.php

Two things I have changed which resolved this for me:

Turned off safe mode in Plesk for PHP.

Slightly altered my cron command to:

0-59 * * * * /usr/bin/php -q httpdocs/API/testSend.php
著墨染雨君画夕 2024-09-26 01:16:34

我遇到了同样的问题,发现通过从 cron 的同一目录运行 php 与从命令行运行 php 是有效的。 cron 条目如下所示:

0-59 * * * * cd <target directory>; /usr/bin/php -q httpdocs/API/testSend.php

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:

0-59 * * * * cd <target directory>; /usr/bin/php -q httpdocs/API/testSend.php
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文