简体   繁体   中英

phpseclib - Errors when running via CRON but not when execute manually

I am using phpseclib 2.0 on my site, installed using composer. I wrote a php function which basically connects to a remote server via SFTP, and download files within a predefined directory. This function is called via CRON using cURL and have been working fine. Last week, it stopped working. I enabled logging and this is what I get.

Severity: User Notice
Message:  Error reading channel data
Filename: Net/SSH2.php
Line Number: 3579

Severity: User Notice
Message:  Connection closed prematurely
Filename: Net/SSH2.php
Line Number: 3025

Severity: User Notice
Message:  Connection closed by server
Filename: Net/SSH2.php
Line Number: 3373

Severity: User Notice
Message:  Expected SSH_FXP_VERSION
Filename: Net/SFTP.php
Line Number: 471

When I checked the table used to store the contents of the downloaded files, none was updated.

The weird thing is that if I were to execute the exact command from the CRON, everything works fine and the table is updated. I have check CROND logs and I can confirm that it is using the same permission as its the same user, ie. root. Anyone have any insight on this issue as I have no idea. I have changed from using cURL to using httpie, but the same result. Works when executed manually on the command line but failed when executed by CRON.

The only server change I did was to upgrade my PHP from version 5.6 to version 7.0. Could that be the cause? If anyone has a solution or any insight on how I can solve this, that would be greatly appreciated. Thanks in advance.

PHP 7 is more strickt to SSL certificates.

Check if the see if the server you're connencting to is giving a proper certificate. or if you can have php ignore the invalid certificate. (less prefered to setting it up properly of course)

--

however this does not explain why you can run the script manually. Only thing I can think of now: is some cert. in the search path when logging in as a user?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM