473,757 Members | 10,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cURL return last effective url, but don't download content?

Suppose I have something like this

$resource = curl_init();
curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
curl_setopt($re source, CURLOPT_URL, '......');
curl_exec($reso urce);
$lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
curl_close($res ource);

I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?

Setting RETURNTRANSFER to FALSE outputs transfer directly
Aug 1 '08 #1
10 4393
On Aug 1, 10:47*pm, Mikhail Kovalev <mikhail_kova.. .@mail.ruwrote:
Suppose I have something like this

* * $resource = curl_init();
* * curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
* * curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
* * curl_setopt($re source, CURLOPT_URL, '......');
* * curl_exec($reso urce);
* * $lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
* * curl_close($res ource);

I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?

Setting RETURNTRANSFER to FALSE outputs transfer directly
Forgot to tell that I'm using CURLOPT_POST & CURLOPT_POSTFIE LDS in
there as well

I'm reading about CURLOPT_NOBODY in the manual, but it says
CURLOPT_HTTPGET , CURLOPT_POST and CURLOPT_HTTPPOS T will reset
CURLOPT_NOBODY

Aug 1 '08 #2
Mikhail Kovalev wrote:
Suppose I have something like this

$resource = curl_init();
curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
curl_setopt($re source, CURLOPT_URL, '......');
curl_exec($reso urce);
$lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
curl_close($res ource);

I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?

Setting RETURNTRANSFER to FALSE outputs transfer directly
Not really, to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 2 '08 #3
On Aug 2, 5:24*am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
* * $resource = curl_init();
* * curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
* * curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
* * curl_setopt($re source, CURLOPT_URL, '......');
* * curl_exec($reso urce);
* * $lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
* * curl_close($res ource);
I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?
Setting RETURNTRANSFER to FALSE outputs transfer directly

Not really, *to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.
A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)
Aug 2 '08 #4
Mikhail Kovalev wrote:
On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Mikhail Kovalev wrote:
>>Suppose I have something like this
$resource = curl_init();
curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
curl_setopt($re source, CURLOPT_URL, '......');
curl_exec($reso urce);
$lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
curl_close($res ource);
I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?
Setting RETURNTRANSFER to FALSE outputs transfer directly
Not really, to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.

A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)
Did you try it? If so, did it work?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 2 '08 #5
On Aug 2, 3:52*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
* * $resource = curl_init();
* * curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
* * curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
* * curl_setopt($re source, CURLOPT_URL, '......');
* * curl_exec($reso urce);
* * $lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
* * curl_close($res ource);
I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?
Setting RETURNTRANSFER to FALSE outputs transfer directly
Not really, *to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.
A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)

Did you try it? *If so, did it work?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
It didn't work. There is a different option CURLOPT_RANGE, where you
can specify how many bytes to download. Alas, not all servers support
this, and I was not lucky this time.

Then I found that cURL allows you to specify a callback function to
write the output by pieces. For each piece the function must return
the exact number of bytes written, otherwise the download aborts. And
so:
curl_setopt($re source, CURLOPT_WRITEFU NCTION, 'hr_func_12A');

function hr_func_12A($re source, $string) { return 0; }

=)
Aug 2 '08 #6
Mikhail Kovalev wrote:
On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Mikhail Kovalev wrote:
>>On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
$resource = curl_init();
curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
curl_setopt($re source, CURLOPT_URL, '......');
curl_exec($reso urce);
$lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
curl_close($res ource);
I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?
Setting RETURNTRANSFER to FALSE outputs transfer directly
Not really, to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.
A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)
Did you try it? If so, did it work?

--
============== ====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attg lobal.net
============== ====

It didn't work. There is a different option CURLOPT_RANGE, where you
can specify how many bytes to download. Alas, not all servers support
this, and I was not lucky this time.
Ah, then that answers your question, doesn't it?
Then I found that cURL allows you to specify a callback function to
write the output by pieces. For each piece the function must return
the exact number of bytes written, otherwise the download aborts. And
so:
curl_setopt($re source, CURLOPT_WRITEFU NCTION, 'hr_func_12A');

function hr_func_12A($re source, $string) { return 0; }

=)
Not a good idea to force an error - that will require extra work by the
remote server to terminate the sending and log the error. But the data
(unless it's huge) is probably already queued and ready to go.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 2 '08 #7
On Aug 2, 10:37*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
* * $resource = curl_init();
* * curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
* * curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
* * curl_setopt($re source, CURLOPT_URL, '......');
* * curl_exec($reso urce);
* * $lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
* * curl_close($res ource);
I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?
Setting RETURNTRANSFER to FALSE outputs transfer directly
Not really, *to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.
A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)
Did you try it? *If so, did it work?
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
It didn't work. There is a different option CURLOPT_RANGE, where you
can specify how many bytes to download. Alas, not all servers support
this, and I was not lucky this time.

Ah, then that answers your question, doesn't it?
Then I found that cURL allows you to specify a callback function to
write the output by pieces. For each piece the function must return
the exact number of bytes written, otherwise the download aborts. And
so:
curl_setopt($re source, CURLOPT_WRITEFU NCTION, 'hr_func_12A');
function hr_func_12A($re source, $string) { return 0; }
=)

Not a good idea to force an error - that will require extra work by the
remote server to terminate the sending and log the error. *But the data
(unless it's huge) is probably already queued and ready to go.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
From 50 to 900 kb

Well, I have no other suggestions. To honestly download the data and
then do nothing with it... doesn't lessen the amount of work for the
remote server.
Aug 2 '08 #8
Mikhail Kovalev wrote:
On Aug 2, 10:37 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Mikhail Kovalev wrote:
>>On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Mikhail Kovalev wrote:
>>Suppose I have something like this
>> $resource = curl_init();
>> curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
>> curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
>> curl_setopt($re source, CURLOPT_URL, '......');
>> curl_exec($reso urce);
>> $lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
>> curl_close($res ource);
>>I'm only interested in the $lastUrl address. Is it possible without
>>wasting bandwidth on downloading the actual trasfer which is at that
>>address ?
>>Setting RETURNTRANSFER to FALSE outputs transfer directly
>Not really, to get the URL, cURL must download the page, if for no
>other reason than to ensure there isn't another redirect.
A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)
Did you try it? If so, did it work?
--
============ ======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@at tglobal.net
============ ======
It didn't work. There is a different option CURLOPT_RANGE, where you
can specify how many bytes to download. Alas, not all servers support
this, and I was not lucky this time.
Ah, then that answers your question, doesn't it?
>>Then I found that cURL allows you to specify a callback function to
write the output by pieces. For each piece the function must return
the exact number of bytes written, otherwise the download aborts. And
so:
curl_setopt($ resource, CURLOPT_WRITEFU NCTION, 'hr_func_12A');
function hr_func_12A($re source, $string) { return 0; }
=)
Not a good idea to force an error - that will require extra work by the
remote server to terminate the sending and log the error. But the data
(unless it's huge) is probably already queued and ready to go.

--
============== ====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attg lobal.net
============== ====

From 50 to 900 kb

Well, I have no other suggestions. To honestly download the data and
then do nothing with it... doesn't lessen the amount of work for the
remote server.
But the work is already done by the server. Everything is most
probably sitting in a queue, just waiting to be sent. Whereas aborting
the transmission requires additional handling for the abnormal state.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 2 '08 #9
Mikhail Kovalev 提到:
On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Mikhail Kovalev wrote:
>>On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
$resource = curl_init();
curl_setopt($re source, CURLOPT_FOLLOWL OCATION, TRUE);
curl_setopt($re source, CURLOPT_RETURNT RANSFER, TRUE);
curl_setopt($re source, CURLOPT_URL, '......');
curl_exec($reso urce);
$lastUrl = curl_getinfo($r esource, CURLINFO_EFFECT IVE_URL);
curl_close($res ource);
I'm only interested in the $lastUrl address. Is it possible without
wasting bandwidth on downloading the actual trasfer which is at that
address?
Setting RETURNTRANSFER to FALSE outputs transfer directly
Not really, to get the URL, cURL must download the page, if for no
other reason than to ensure there isn't another redirect.
A header is sufficient for this, or am I wrong?
(Which is exactly what CURLOPT_NOBODY does, btw.)
Did you try it? If so, did it work?

--
============== ====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attg lobal.net
============== ====

It didn't work. There is a different option CURLOPT_RANGE, where you
can specify how many bytes to download. Alas, not all servers support
this, and I was not lucky this time.

Then I found that cURL allows you to specify a callback function to
write the output by pieces. For each piece the function must return
the exact number of bytes written, otherwise the download aborts. And
so:
curl_setopt($re source, CURLOPT_WRITEFU NCTION, 'hr_func_12A');

function hr_func_12A($re source, $string) { return 0; }

=)

IT manager 蛇***眼edm und yau (email擬似ya* *****@hotmail.c om)
全香港最濺 IT Manager, 見*著西裝 返工. 著得好過佢 就問**竟 點諗, *小人,
痴撚線
5:00pm俾個job *做, 跟住就自己 做到11點搞 佢, 第2日就小 *, 話*搞唔掂 , 唔
撚洗放工呀

最撚柒就係 呢條友啦, 搞個爛網出 黎, 大家去睇下 :
網址擬似www.funzy.com

有幾爛? 仆街, 用IE6開會* 機架, 真係唔撚知 用乜野skill 以寫撚到h ang機.

成條team朝9 10, 搞個爛網得 個2個function 仔, 唔係hang機 係*link, 仲話寫
web要都唔知 乜撚野skill set, 食屎啦, 小*生寫個 web都唔撚會 hang機啦

個個同事想 放工都要驚 呢樣驚個樣 , *張*o的 春濺賣就 撚好叫人 齊同*濺
賣, 人地都有屋 企, *唔撚放工 就*o既事, 除撚左打工 都唔撚知搞 個web未, 屎坑關刀

大家多多張 呢個網發佈 出去, 聲討呢種小 人

Counter
1
Aug 12 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2487
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its content display? I've tried the following class methods for display and I have most everything working until I get to a URL that requires $_SESSION: class Timer extends View {
6
3355
by: benji | last post by:
I have set up a system to download datafeeds in pain text or zipped. The download part of this system uses the curl extension to download the files. All was well when I tested it with various datafeeds in zipped and unzipped formats until I came to download zipped files from the affiliate program we are starting with. I have verified that the datafeeds download properly in Internet Explorer but interestingly they also fail in Firefox.
0
1467
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what you deemed an innocent post? The following tips will not only help you, they will help us help you. Please note: The latest changes to this document are marked with a | at the left-most side of the line that has been changed.
4
12157
by: BinnyVA | last post by:
Hi, I am using PHP 5.1.2 with curl enabled. But whenever I try to use curl to fetch a url, it fails - 'curl_exec()' returns nothing. But if I try to execute the same file in CLI - like 'php curl.php', the script works properly. However if I try it in a browser, nothing is returned. The code is...
0
3368
by: xerc | last post by:
I am trying to create a generic function I can call to download all files from a single remote FTP directory -- using CURL. I want to multi-thread it, but need to get the single thread functionality working first before I tackle that. Anyway, in my function I can list all the files, but the function I have, no matter how I try, will only return one file -- the last file. My for() loop seems pretty straightforward, so not sure why only the...
1
4908
by: c1pkw | last post by:
Hi there, Im having a real heap of trouble with PHP and cURL My aim is to use this code (or something like it) to submit 2 fields to a remote server (using GET) and receive back 6 fields (again with GET). When I run the function below, I get back a 401 unauthorized error although the Username and Password are correct. Presumably then, they are not reaching the remote server at all or in the correct state. Problem is, I know so...
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.