synology php ftp_ssl_connect - Call to undefined function - php

First time asking a question here, please be gentle :-)
I'm writing a PHP command-line script on a Synology box to fetch files via ftps, and start out with this bit:
$ftp = ftp_ssl_connect("ftp.example.com");
When run from the command line, I get
Fatal error: Call to undefined function ftp_ssl_connect() in ...
phpinfo() tells me:
...
Registered PHP Streams => php, file, glob, data, http, ftp, https, ftps, zip, compress.zlib, compress.bzip2
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
...
openssl
OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.1p-fips 9 Jul 2015
OpenSSL Header Version => OpenSSL 1.0.1p-fips 9 Jul 2015
and /etc/php/conf.d/extensions.ini contains extension = openssl.so (without an initial ;)
It seems to me that all the prerequisites for ftp_ssl_connect() are in place.
fwiw:
$ uname -a
Linux DiskStation01 2.6.32.12 #5644 Wed Oct 28 12:36:45 CST 2015 armv5tel GNU/Linux synology_88f6282_213
What would be the next place to look?

Type php -m to see the compiled in modules, as PHP does not ship the FTP extension by default if not on Windows. Calling phpinfo() should also show the compiler switches used, and if they include --enable-ftp.
The curious thing is I just tried this on an RS812 of mine, and it shows both the FTP and OpenSSL moodules as included, and it works fine:
nas-name> php -r "ftp_ssl_connect('test');"
PHP Warning: ftp_ssl_connect(): php_network_getaddresses: gethostbyname failed
in Command line code on line 1
This indicates the ftp_ssl_connect is working but not being able to parse the supplied host name. I have no idea why yours would be different unless you compiled PHP yourself.

As mentioned in Niels solution the ftp-Module is missing in the default installation. I needed the module in the CLI version of PHP, but it was unavailable on all four of my Synology Devices (DS 412+, DS 410, RS812+ and RS814+).
Enabling the module in the Web Station settings did not help, but there is a solution for the CLI version in a Synology Forum Entry:
make sure that the ftp extension is selected within php settings of Web Station.
then edit /etc/php/php.ini to include a line like this:- extension = /volume1/#appstore/PHP5.6/usr/local/lib/php56/modules/ftp.so
that's it. No restarting of Web Station or the NAS is required, as php loads itself from the commandline each time a call is made to php.

Related

Use of undefined constant CURLOPT_TCP_FASTOPEN

If i use the CURLOPT_TCP_FASTOPEN option in my code , then i get the following error.
Use of undefined constant CURLOPT_TCP_FASTOPEN - assumed
'CURLOPT_TCP_FASTOPEN'
The CURLOPT_TCP_FASTOPEN is a supported option in php 7.4.5 interface .
php -v
PHP 7.4.5 (cli) (built: Apr 14 2020 12:54:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies
curl -V
curl 7.70.0 (x86_64-redhat-linux-gnu) libcurl/7.70.0 NSS/3.44 zlib/1.2.7 libpsl/0.7.0 (+libicu/50.1.2) libssh2/1.9.0 nghttp2/1.31.1
Release-Date: 2020-04-29
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB PSL SPNEGO SSL UnixSockets
What am i doing wrong here ?
Edit 1:
Here are additional info corresponding to YouriKoeman's overview
Kernel version : 3.10.0-1062.12.1.el7.x86_64
OS : unix (Centos 7.x)
curl --tcp-fastopen -L http://www.google.com return the following error:
curl: (55) Send failure: Operation not supported for curl --tcp-fastopen -L http://www.google.com
I chose to answer in a more broad way to hopefully help more poeple when they encounter issues relating to this and google for answers
(Note: php runtime and Loaded extensions can differ between the CLI and when accessed from a webserver).
What are the system requirements for this feature?
The feature CURLOPT_TCP_FASTOPEN you want to use has some system requirements that have to be met
They are the following:
You must have Kernel version > 3.6 (linux)
You must have PHP 7.0.7 or higher
You must have Curl(program) AND php{your/version}-curl 7.49.0 or higher
You must have a *nix type of operating system (macos, linux, bsd)
how to debug What requirement is not being met?
The fact that the constant is not defined is a red flag that one of these dependencies is not met, but how do i figure out which?
kernel version
This one is easy, run the following command:
uname -r.
It must be greater than 3.6
Curl version and build options
The best way to check if the functionality is available in curl is to call curl from the cli with this option, like:
curl --tcp-fastopen -O http://google.com
If this request goes successfully, curl is configured correctly on your system, so the problem lies within php
PHP version and extensions
For webserver
use phpinfo() to check if the php version is greater than 7.0.7 And that the php-curl extensions are loaded
For CLI
in the command line type php -v the version should be greater than 7.0.7.
To check the extensions type the following into your command line php -m | grep curl this command should return curl, if nothing is returned the curl extension is not loaded for the php cli.
The issue was that tcp fast open is not enabled by default until kernel version 3.13.
To enable TCP Fast Open on Centos 7:
1.Add tcp_fastopen in sysctl.d
echo "net.ipv4.tcp_fastopen=3" > /etc/sysctl.d/30-tcp_fastopen.conf
2.Restart sysctl
systemctl restart systemd-sysctl
3.Verify sysctl setup for tcp_fastopen
cat /proc/sys/net/ipv4/tcp_fastopen should output 3

Why is only php short opening <? working on v5.6 and <?php not?

My client gave me a login to their ftp and I uploaded a code. Unfortunatelly when I try running a website I get PHP Parse error no matter what it is there (as if PHP would not be functioning properly).
Examples:
index.php
<?php
echo 'test';
gives me an error:
PHP Parse error: syntax error, unexpected ''test'' (T_CONSTANT_ENCAPSED_STRING)
What if I try php functions?
<?php
phpinfo();
gives me an error:
PHP Parse error: syntax error, unexpected 'phpinfo' (T_STRING)
Does anyone have any clue what is going on?
P.S. Client does not want to me to give login credentials to server since "there are a lot of important data"...
UPDATE
Using <? or <?= instead of <?php did the job. But I would love to have <?php working instead since project contains of hundreds of php files opening with <?php.
phpinfo() information:
PHP Version 5.6.31
System Linux cp60.webserver.pt 2.6.32-673.26.1.lve1.4.29.el6.x86_64 #1
SMP Tue Jun 20 13:27:00 EDT 2017 x86_64 Build Date Jul 17 2017 09:37:47
Server API CGI/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /opt/alt/php56/etc
Loaded Configuration File /opt/alt/php56/etc/php.ini
Scan this dir for additional .ini files /opt/alt/php56/link/conf
Additional .ini files parsed /opt/alt/php56/link/conf/alt_php.ini
PHP API 20131106
PHP Extension 20131226
Zend Extension 220131226
Zend Extension Build API220131226,NTS
PHP Extension Build API20131226,NTS
Debug Build no
Thread Safety disabled
Zend Signal Handling disabled
Zend Memory Manager enabled
Zend Multibyte Support provided by mbstring
IPv6 Support enabled
DTrace Support disabled
Registered PHP Streams https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports tcp,
udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters zlib., bzip2., convert.iconv., string.rot13,
string.toupper, string.tolower, string.strip_tags, convert.,
consumed, dechunk, mcrypt., mdecrypt.
In the end it was encoding issue by FileZilla... I change Transfer option to "Binary" and now it works as usual.
I've read a lot of issues with php file encoding while transfering using ftp and most of them have symptoms as mine (php opening tag not working). I will leave the question so someone with the same problem would find a solution.

PHP OpenSSL undefined constant OPENSSL_ALGO_DSS1

I am running PHP 5.2.13 on a Windows Server 2008 R2 machine (Windows 7 equivalent).
I'm mostly writing this just because I get a google dead end on searching for the warning and I'm trying to add something for it.
I am getting the following notice / warning:
Use of undefined constant OPENSSL_ALGO_DSS1 - assumed 'OPENSSL_ALGO_DSS1'
openssl_verify() expects parameter 4 to be long, string given
When running this line of code:
return openssl_verify($data, $signature, $this->getPublicKey(), OPENSSL_ALGO_DSS1);
Obviously the second warning is caused by the first.
However the problem isn't that the OpenSSL library isn't loaded, as I have the following output from phpinfo:
OpenSSL support enabled
OpenSSL Version OpenSSL 0.9.8k 25 Mar 2009
This is working on all other machines that it has been tested on, so there is something machine specific.
The only difference I have spotted is the following from phpinfo:
Registered Stream Socket Transports tcp, udp
vs on machines where it is working:
Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tls
But I'm not sure if that's a red herring or not.
My solution for the problem was to uninstall PHP completely and run the php-5.2.13-nts-x86.msi installer and install the OpenSSL library through there.
I had done a manual installation of the OpenSSL library rather than using the Windows installer.
I now do have the following in phpinfo:
Registered PHP Streams php, file, data, http, ftp, compress.zlib, https, ftps
Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tls
As far as I can tell even according to the openssl installation documentation there shouldn't be a requirement to have to install using the installer. On other machines I haven't had this problem. Altering the 'Registered Stream Socket Transports' to include ssl should only require installing the open_ssl library and adding a line to the php.ini file e.g. this answer.

Unable to install Google App Engine for Php in Ubuntu 15.04

I downloaded the Google App Engine SDK for PHP but I am having problems with the installation of the PHP interpreter. I downloaded the source code from the link given but when I try to compile php the command make terminates with this error:
/bin/bash /home/david/Google/appengine-php-master/php-src/libtool --silent --preserve-dup-deps --mode=compile cc -Iext/jsonc/ -I/home/david/Google/appengine-php-master/php-src/ext/jsonc/ -DPHP_ATOM_INC -I/home/david/Google/appengine-php-master/php-src/include -I/home/david/Google/appengine-php-master/php-src/main -I/home/david/Google/appengine-php-master/php-src -I/home/david/Google/appengine-php-master/php-src/ext/date/lib -I/home/david/Google/appengine-php-master/php-src/ext/ereg/regex -I/libxml2 -I/home/david/Google/appengine-php-master/php-src/ext/sqlite3/libsqlite -I/home/david/Google/appengine-php-master/php-src/TSRM -I/home/david/Google/appengine-php-master/php-src/Zend -I/include -g -O2 -fvisibility=hidden -c /home/david/Google/appengine-php-master/php-src/ext/jsonc/json.c -o ext/jsonc/json.lo
In file included from ext/jsonc/json-c/json_inttypes.h:5:0,
from ext/jsonc/json-c/json_object.h:16,
from ext/jsonc/json-c/linkhash.h:16,
from ext/jsonc/json-c/json.h:22,
from /home/david/Google/appengine-php-master/php-src/ext/jsonc/json.c:34:
ext/jsonc/json-c/json_config.h:2:23: fatal error: ../config.h: No such file or directory
#include "../config.h"
^
compilation terminated.
Makefile:725: recipe for target 'ext/jsonc/json.lo' failed
make: *** [ext/jsonc/json.lo] Error 1
In fact there is no such config.h file in that directory so I can't understand how to solve this problem.
So I decided to search online the source code of PHP 5.4.19 and I compiled and installed it and everything worked. I followed all the other installation steps and everything worked.
Now if I start the server with the command
google_appengine/dev_appserver.py --php_executable_path=/usr/local/bin/php-cgi --php_gae_extension_path=/home/david/Google/appengine-php-extension-master/modules/gae_runtime_module.so my_app/
I get:
INFO 2016-03-25 15:04:19,209 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO 2016-03-25 15:04:19,797 sdk_update_checker.py:257] The SDK is up to date.
INFO 2016-03-25 15:04:19,901 api_server.py:205] Starting API server at: http://localhost:51913
INFO 2016-03-25 15:04:19,907 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-03-25 15:04:19,909 admin_server.py:116] Starting admin server at: http://localhost:8000
ERROR 2016-03-25 15:04:21,270 php_runtime.py:348] The PHP runtime is not available
Traceback (most recent call last):
File "/home/david/Google/google_appengine/google/appengine/tools/devappserver2/php_runtime.py", line 344, in new_instance
self._check_binaries(php_executable_path, gae_extension_path)
File "/home/david/Google/google_appengine/google/appengine/tools/devappserver2/php_runtime.py", line 286, in _check_binaries
cls._check_gae_extension(php_executable_path, gae_extension_path, env)
File "/home/david/Google/google_appengine/google/appengine/tools/devappserver2/php_runtime.py", line 241, in _check_gae_extension
ext_stdout))
_PHPEnvironmentError: "/usr/local/bin/php-cgi -m" returned an error [-6]
[libprotobuf FATAL google/protobuf/stubs/common.cc:61] This program requires version 3.0.0 of the Protocol Buffer runtime library, but the installed version is 2.6.1. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/home/david/Google/appengine-php-extension-master/remote_api.pb.cc".)
terminate called after throwing an instance of 'google::protobuf::FatalException'
what(): This program requires version 3.0.0 of the Protocol Buffer runtime library, but the installed version is 2.6.1. Please update your library. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/home/david/Google/appengine-php-extension-master/remote_api.pb.cc".)
Accordingly to the message the problem should be in the version of libprotobuf9 library. I have that library installed in my system (ubuntu 15.04) and in fact the version is 2.6.1. But by following the installation steps I installed protoc-3.0.0-beta-2-linux-x86_64 and protobuf-3.0.0-beta-2 in /usr. So, why does appengine use the wrong version of the library?
I thought about removing libprotobuf9 from my system but if I run sudo apt-get remove libprotobuf9 the list of packages that need to be removed is very big and contains things like
gnome-bluetooth gnome-calculator gnome-contacts
gnome-disk-utility gnome-font-viewer gnome-keyring gnome-mahjongg gnome-mines gnome-orca gnome-power-manager gnome-screensaver
gnome-screenshot gnome-session-bin gnome-session-canberra gnome-sudoku gnome-system-log gnome-system-monitor gnome-terminal
to me it doesn't seem a good idea to remove them. What's the solution to my problem?

PHP Extension (memcache|memcached) not showing in phpinfo() but showing in php -m and php -i?

I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.

Categories