Jump to content

can't decide which curl to use


Go to solution Solved by gizmola,

Recommended Posts

 

In trying to get the text off a particular website, I've used two different ways, both of which seem to work fine & give the exact same results.. 

I was wondering if anyone could give me any insight or recommendations why one way might be any better or worse than the other .

I've used these two ways:

$ch1=curl_init();
curl_setopt($ch1,CURLOPT_URL,$link1);
curl_setopt($ch1,CURLOPT_RETURNTRANSFER, true);
$text1=curl_exec($ch1);
// or
$text1 = shell_exec('curl '.$link1 );

The second way seems easier & speedwise they both are about the same 

I've also tried "file_get_contents" which also gives the same results but is obviously slower. 

Link to comment
https://forums.phpfreaks.com/topic/327110-cant-decide-which-curl-to-use/
Share on other sites

  • Solution
  On 3/23/2025 at 12:20 AM, garyed said:

 

In trying to get the text off a particular website, I've used two different ways, both of which seem to work fine & give the exact same results.. 

I was wondering if anyone could give me any insight or recommendations why one way might be any better or worse than the other .

I've used these two ways:

$ch1=curl_init();
curl_setopt($ch1,CURLOPT_URL,$link1);
curl_setopt($ch1,CURLOPT_RETURNTRANSFER, true);
$text1=curl_exec($ch1);
// or
$text1 = shell_exec('curl '.$link1 );

The second way seems easier & speedwise they both are about the same 

I've also tried "file_get_contents" which also gives the same results but is obviously slower. 

Expand  

The two ways are significantly different. 

The first way is the way you should do this.  It uses the curl extension that is built into PHP.  

The 2nd way is creating a system shell and then executing a shell command that in your case happens to be the curl command.   Many things could go wrong, and you will not have visibility into those issues.  It is a less direct method, and doesn't have the same level of access to curl options and results.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.