1

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?

shadyyx
  • 15,825
  • 6
  • 60
  • 95
mootymoots
  • 4,545
  • 9
  • 46
  • 74
  • 2
    PHP running in the browser may be using a different php.ini file than from cron or the console (CLI mode). "Failed to enable crypto" makes me wonder if some php extension isn't loading in CLI mode. Open up a terminal and type `php -i | grep php.ini`. This will show you the php.ini being used, and compare it to the one used when in the browser by looking at `phpinfo()` through a browser. – Fanis Hatzidakis Sep 12 '10 at 20:13
  • Hi - They are both etc/php.ini – mootymoots Sep 12 '10 at 20:29
  • It is worth noting I am using CRONTAB via Plesk - does this make a difference? – mootymoots Sep 12 '10 at 20:32

3 Answers3

1

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

ron
  • 726
  • 11
  • 16
1

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
bvs
  • 1,087
  • 13
  • 19
0

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
mootymoots
  • 4,545
  • 9
  • 46
  • 74