curl_init() error - Call to undefined function

Web hosting discussion, programming, and shared and dedicated servers.
6 posts Page 1 of 1
by rky » Thu Sep 27, 2018 12:51 pm
I have a .php script that is designed to periodically (cron job), read a MySQL table for new entries and send notifications to Google's Firebase Cloud messaging, for distribution to the appropriate mobile devices. Reading from the database works just fine, but when I prepare to send the message to FCM (Firebase Cloud Messaging), from within the php script sendNotification.php, I receive the following error: "Fatal error: Call to undefined function curl_init() in /web/rky/myremotespy.com/test/rpi_ht/sendNotification.php on line 86." This exact same php script (no changes), used to work in early 2018. I've seen another post in this forum suggesting that there are needed/required lines in .htaccess, there IS a .htaccess in the same directory as sendNotification.php with the following contents:

Action php-cgi /cgi-bin/php55
AddHandler php-cgi .php

From what I can tell from looking at /opt/php53/lib/php.ini ( as /opt/php53/bin/php -i indicated that was the config file being used ), it appears that the curl_php extension is not loaded.

What do I need to do to be able to use the curl library in my php script, in a sub directory of a domain hosted by Sonic ?

Thank You
Robert Young
by drew.phillips » Thu Sep 27, 2018 4:47 pm
Hi Robert,

Our PHP 5.3, 5.5, and 5.6 installations all have curl support built in. I'd suggest changing the "Action" to use PHP 5.6 though, since this is a much newer build than the others, and has a more recent version of cURL and OpenSSL.

Code: Select all

Action php-cgi /cgi-bin/php56
AddHandler php-cgi .php
The PHP settings that go in your .htaccess file are going to be per site.

Is the cron job running from our shell server? This PHP version is separate from what you'd see on the hosting services, but does have curl support.

If possible, move the .htaccess file into your site's root at /home/www_pages/rky/myremotespy.com. If the script that executes is in a higher directory, the .htaccess file in the rpi_ht directory won't have any effect.
Drew Phillips
Programmer / System Operations, Sonic.net
by rky » Fri Sep 28, 2018 10:02 am
Well, I've updated the .htaccess to 5.6, and added it to the base directory of myremotespy. However that seems irrelevant according to your answer, since as for testing I'm executing it from a shell command line. Below is the command and response:

************************************************************************************************************
_[/home/r/rky]_(rky@sh)_
/opt/php53/bin/php -f /nfs/WWW_pages/rky/myremotespy.com/test/rpi_ht/sendNotification.php

Expiration Query Statement: SELECT * FROM notifications WHERE acknowledged='No'
Notification Select returned 29 rows.
Notification - From: THT_ID:6eacbbf9 At: 70.115.140.50 On: 2018-09-18 11:22:14 From Sensor: One Expires: 2018-09-18 11:25:14 Associated Images: 2018-09-18_112159c1.jpg 2018-09-18_112209c2.jpg
Query Statement: SELECT * FROM user_credentials WHERE trap_id LIKE 'THT_ID:6eacbbf9'
User Select returned 3 rows.
Sending Notification - To: THT_App:442ee4486f0e07d7 At:

Fatal error: Call to undefined function curl_init() in /web/rky/myremotespy.com/test/rpi_ht/sendNotification.php on line 86
_[/home/r/rky]_(rky@sh)_
**********************************************************************************************************
As I mentioned in my original post, this used to work earlier this year on a server I configured, and late last year on Sonic's server, and I've not made any changes to the code since then. I know it's not your responsibility to debug my code, but I can't see how: " Fatal error: Call to undefined function curl_init() in /web/rky/myremotespy.com/test/rpi_ht/sendNotification.php on line 86" is something wrong with my code. Obviously PHP is working, because it does access the database and obtains 29 records, you say Curl is "built in," so I am at a loss to understand why curl_init() is undefined. Feel free to execute the above command from a shell to see if you get a different result.

This is for a project I'm being paid for, so I really need to solve this as soon as possible.

Thanks,
Robert Young
by drew.phillips » Fri Sep 28, 2018 10:40 am
Hi Robert,

Thanks for the more detailed command and output. Instead of using /opt/php53/bin/php, use the default PHP install on the shell server. Just "php" or /usr/bin/php. This is PHP 5.4 with curl built in. We don't have any additional PHP binaries available on the shell server at this time.

That should solve the problem and get the script to run properly.
Drew Phillips
Programmer / System Operations, Sonic.net
by rky » Fri Sep 28, 2018 12:23 pm
Okay thanks, the script does now run, the mobile device doesn't get the notification, but that problem is somewhere else. FWIW I got the advice to use that command from an answer to a post I made in this support forum about a year ago: viewtopic.php?t=4736
by drew.phillips » Fri Sep 28, 2018 2:27 pm
The shell server was upgraded in recent months and everything was moved to a new host. I believe PHP 5.3 may have been rebuilt early on, and if that is the case, it looks like cURL was forgotten during the rebuild. Since the new host has the CentOS 7 PHP 5.4 distro built in with cURL, this is better to use at this point.

If newer PHP versions are needed, we are open to installing them but so far 5.4 has been working for the cron jobs dealing with PHP and interaction with sites.

That I believe is the correct explanation for why the working cron job stopped recently.

Email from the shell host should still work, but there may be issues with Gmail deferring our messages. Is the notification by chance going to a Google address?
Drew Phillips
Programmer / System Operations, Sonic.net
6 posts Page 1 of 1

Who is online

In total there are 22 users online :: 1 registered, 0 hidden and 21 guests (based on users active over the past 5 minutes)
Most users ever online was 999 on Mon May 10, 2021 1:02 am

Users browsing this forum: Bing [Bot] and 21 guests