473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

Suppose I have something like this

$resource = curl_init();
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_URL, '......');
curl_exec($resource);
$lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
curl_close($resource);

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 4359
On Aug 1, 10:47*pm, Mikhail Kovalev <mikhail_kova...@mail.ruwrote:
Suppose I have something like this

* * $resource = curl_init();
* * curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
* * curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
* * curl_setopt($resource, CURLOPT_URL, '......');
* * curl_exec($resource);
* * $lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
* * curl_close($resource);

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_POSTFIELDS in
there as well

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

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

$resource = curl_init();
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_URL, '......');
curl_exec($resource);
$lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
curl_close($resource);

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*******@attglobal.net
==================
Aug 2 '08 #3
On Aug 2, 5:24*am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
* * $resource = curl_init();
* * curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
* * curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
* * curl_setopt($resource, CURLOPT_URL, '......');
* * curl_exec($resource);
* * $lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
* * curl_close($resource);
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...@attglobal.netwrote:
>Mikhail Kovalev wrote:
>>Suppose I have something like this
$resource = curl_init();
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_URL, '......');
curl_exec($resource);
$lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
curl_close($resource);
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*******@attglobal.net
==================
Aug 2 '08 #5
On Aug 2, 3:52*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
* * $resource = curl_init();
* * curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
* * curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
* * curl_setopt($resource, CURLOPT_URL, '......');
* * curl_exec($resource);
* * $lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
* * curl_close($resource);
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...@attglobal.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($resource, CURLOPT_WRITEFUNCTION, 'hr_func_12A');

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

=)
Aug 2 '08 #6
Mikhail Kovalev wrote:
On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Mikhail Kovalev wrote:
>>On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
$resource = curl_init();
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_URL, '......');
curl_exec($resource);
$lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
curl_close($resource);
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...@attglobal.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_WRITEFUNCTION, 'hr_func_12A');

function hr_func_12A($resource, $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*******@attglobal.net
==================
Aug 2 '08 #7
On Aug 2, 10:37*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
* * $resource = curl_init();
* * curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
* * curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
* * curl_setopt($resource, CURLOPT_URL, '......');
* * curl_exec($resource);
* * $lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
* * curl_close($resource);
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...@attglobal.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_WRITEFUNCTION, 'hr_func_12A');
function hr_func_12A($resource, $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...@attglobal.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...@attglobal.netwrote:
>Mikhail Kovalev wrote:
>>On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Mikhail Kovalev wrote:
>>Suppose I have something like this
>> $resource = curl_init();
>> curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
>> curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
>> curl_setopt($resource, CURLOPT_URL, '......');
>> curl_exec($resource);
>> $lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
>> curl_close($resource);
>>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...@attglobal.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_WRITEFUNCTION, 'hr_func_12A');
function hr_func_12A($resource, $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...@attglobal.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*******@attglobal.net
==================
Aug 2 '08 #9
Mikhail Kovalev 提到:
On Aug 2, 3:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Mikhail Kovalev wrote:
>>On Aug 2, 5:24 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mikhail Kovalev wrote:
Suppose I have something like this
$resource = curl_init();
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_URL, '......');
curl_exec($resource);
$lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
curl_close($resource);
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...@attglobal.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($resource, CURLOPT_WRITEFUNCTION, 'hr_func_12A');

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

=)

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

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

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

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

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

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

Counter
1
Aug 12 '08 #10
On Aug 1, 9:47 pm, Mikhail Kovalev <mikhail_kova...@mail.ruwrote:
Suppose I have something like this

$resource = curl_init();
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resource, CURLOPT_URL, '......');
curl_exec($resource);
$lastUrl = curl_getinfo($resource, CURLINFO_EFFECTIVE_URL);
curl_close($resource);

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
I don't know if this is any help to you, because I don't really
understand what you're trying to do and I've never really had much
exposure to curl before, but HTTP supports a HEAD mode. When a HTTP
request occurs it is usually done with a GET, meaning "Send me this
file". If you send HEAD instead of GET the server interoperates it as
"Send me the headers you would have sent if you had sent me the whole
file as normal, but don't send the actual file". Maybe if you use
HEAD to access the data you want you can avoid the overhead of
fetching the whole file. There are restrictions on HEAD, however, you
can't use POST to send the receiver anything. I don't think you can
use GET variables (The ?foo=bar&baz=quux style query strings) either,
but if you can live with these restrictions then it should be helpful
to you.
Aug 12 '08 #11

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

Similar topics

0
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...
6
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...
0
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...
4
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...
0
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.