Solved

Cron jobs and CURL php module

Posted on 2004-08-24
16
715 Views
Last Modified: 2012-06-27
Hi
I have a PHP function that uses CURL. When I load the page in my browser, all code is being executed like it should. However, when the script is called as a cron job, I get a cron result mail with following error:

"This SMS API class can not work without CURL PHP module!"

Is this CURL module not loaded when I run it as a cron job?
This is how I call (all) cronjob pages:

"/usr/bin/php /home/puca/public_html/include/script.php"

(all other scripts work this way, only CURL gives an error..)
0
Comment
Question by:puca01
  • 5
  • 2
  • 2
  • +5
16 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 11883908
do a /usr/bin/php -m and see if the curl-module is available.
If not maybe you could load it try

<?php
if(dl('curl.so')) { echo "curl loaded";} else {echo "not loadable";}

and watch teh output on the command-line. If it is notavailable you have to recomplie the CLI-php
0
 
LVL 1

Author Comment

by:puca01
ID: 11884059
It is not in the module list.
I tried the code and got this warning:

<b>Warning</b>:  dl(): Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20020429/curl.so' - /usr/lib/php/extensions/no-debug-non-zts-20020429/curl.so: cannot open shared object file: No such file or directory in <b>/home/puca/public_html/testcurl.php</b> on line <b>3</b><br />
not loadable

I'm not able to recompile because it is a shared hosting. But how come CURL works when I acces the script with a browser?
Can't I just call the script an other way or something like that?
0
 
LVL 1

Author Comment

by:puca01
ID: 11885201
Points now 125 for the one that can solve this
(and again: I cannot recompile, it needs to be doen with the CURL currently working for browser acces)
0
 
LVL 3

Expert Comment

by:Yasir_Malik
ID: 11885512
Perhaps you can compile the module yourself, store it in your account, and then use the absolute path to the module.  I have no idea if that will work.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 11885620
No absolute path will work for dl
file /usr/share/extensions/no-debug-non-zts-20020429//home/xyz/curl.so not found

but you could compile a php on a linux box with the modules you need, upload that binary and then use that binary for your cron-job
e.g /home/puca/bin/php

maybe you can even compile that php on the box for your pages if you have shell-access, so all libraries will match.
0
 
LVL 1

Author Comment

by:puca01
ID: 11885642
I'm not an expert in linux so I don't know if I can do that.
Is there anybody who can explain to me why the thing works when i load it in a browser and not with commandline execution?

Or just how i can simulate browser acces with a commandline execution?
0
 
LVL 1

Expert Comment

by:LiquidIce911
ID: 11886741
Try other methods of doing PHP cronjobs like:

or other methods include..

/usr/bin/wget http://yoursite.com/page.php

or

lynx --dump http://yoursite.com/cronjob.php >/dev/null
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:Yasir_Malik
ID: 11887149
If this /usr/share/extensions/no-debug-non-zts-20020429//home/xyz/curl.so won't work, maybe you can do
dl("../../../..home/xyz/curl.so")

But if you have Lynx, you could do as LiquidIce911 suggested.
0
 
LVL 1

Author Comment

by:puca01
ID: 11887962
@LiquidIce

got these error messages:
/bin/sh: line 1: /usr/bin/lynx: Permission denied
/bin/sh: line 1: /usr/bin/wget: Permission denied

Is there an easy way to get the lynx binary so I can put it in my own folder and with sufficient rights?

@Yasir

This was just a warning when i ran this line of code:
if(dl('curl.so')) { echo "curl loaded";} else {echo "not loadable";}

So I'm not referring to that path, the server locates it itself.
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 11888571
I've run into this before.  I think I can help.

First run phpinfo(); from a browser. Under configuration / PHP Core, find include_path.  Copy the value listed.

Then at the top of your script add this line...

    ini_set("include_path", "whatever/path/phpinfo/showed;maybe/more/then/one");

When your script runs from the browser, apache is setup and knows where to find everything.  When it's run from the command line you sometimes find that your running a whole different version of php that may not have been configured the same.  If you really want to debug things, you can check the results of phpinfo when run from the browser, compared to when run from cron.

See http://php.net/phpinfo for a user comment showing a small script to email phpinfo back to you.

------
As far as making lynx or wget work, if you have read permission, try this...

cp /usr/bin/lynx .
cp /usr/bin/wget .
chmod +x lynx
chmod +x wget

You now have the binaries in your local directory and ready to execute.  It may not work, depends on the file permissions your admin has setup.
0
 
LVL 1

Author Comment

by:puca01
ID: 11894747
I've tried what you said about the include_path, however it doesn't work. I still get the same error:
This SMS API class can not work without CURL PHP module!

I alerady tried copying the binary, but I do not have permissions for that..

I have found a workaround myself: I call a script that does a http request to the other page. It works this way although it's not a professional solution :-)
0
 
LVL 18

Expert Comment

by:arantius
ID: 11895034
As for the reason that this is happening, there are two "versions" of PHP.  One here is compiled into apache, and loads once when apache loads, and is called once for each page loaded.  The other is /usr/bin/php which is loaded each time you call it.  I have to wonder if the hosting company knows what they're doing if the two versions are compiled with different modules.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 12549925
PAQ it - the last comment of the asker is a solution.

Venabili
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12574374
Closed, 125 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now