|
 |
curl_exec (PHP 4 >= 4.0.2, PHP 5) curl_exec -- Выполняет запрос CURL Описаниеmixed curl_exec ( resource ch )
Эта функция вызывается после инициализации сеанса и установки всех
необходимых параметров. Именна эта функция фактически выполняет
требуемую операцию.
Пример 1.
Инициализация сеанса CURL и загрузка web-страницы
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
|
|
Замечание:
Если вам нужно, чтобы эта функция вернула результат, а не вывела
его в браузер, используйте опцию CURLOPT_RETURNTRANSFER с функцией
curl_setopt().
curl_exec
Jrgen Tjern
08-Mar-2005 06:12
If you've got problems with curl_exec not working, you should rather check curl_errno and curl_error than using commandline curl, like so:
(since this is easier, and also allows you to check for errors runtime, which is a vital part of any well-design piece of code. ;)
<?php
$creq = curl_init();
curl_setopt($creq, CURLOPT_URL, "http://www.foo.internal");
curl_exec($creq);
if (curl_errno($creq)) {
print curl_error($creq);
} else {
curl_close($creq);
}
?>
landon at phazeforward dot com
01-Dec-2004 03:43
If your curl installation is not compiled with SSL support you will beat your head against a wall when trying to figure out why curl_exec() is failing to fail or do anything else ...
If you run into a situation where your call to curl_exec is not returning anything you should try the same call with the command line curl
fifa_2k [-at-] sina [-dot-] com
28-Oct-2004 11:29
With php 4.3.9 or higher,you can upload file to ftp server on win32 system
<?php
function curl_upload($src) {
$fn = basename($src);
$dest = "ftp://user:passwd@server.com/incoming/$fn";
$ch = curl_init();
$fp = fopen($src,"r");
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 300);
curl_setopt($ch, CURLOPT_URL, $dest);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($src));
curl_exec($ch);
fclose ($fp);
$errorMsg = '';
$errorMsg = curl_error($ch);
$errorNumber = curl_errno($ch);
curl_close($ch);
return $errorNumber;
}
?>
lower version php (I tried on php 4.3.3) on win32 can't do this and may cause php crash even you use CURLOPT_READFUNCTION.
sybren at thirdtower dot com
01-Jul-2003 07:00
If you see a "0" at the end of the output, you might want to switch to HTTP/1.0:
curl_setopt($ch, CURLOPT_HTTP_VERSION, 1.0);
nagyp at hunaxon dot hu
26-Apr-2003 05:22
fyi:
It returns false if there's an error while executing the curl session, no matter how CURLOPT_RETURNTRANSFER is set.
colins at infofind dot com
24-Apr-2002 04:42
Checking the source, curl_exec seems to return FALSE on failure, TRUE on success (unless CURLOPT_RETURNTRANSFER is set 1, and then it returns the returned data).
ppruett at webengr dot com
28-Feb-2002 07:06
fyi - if you are having problems getting a
webpage to display in your webpage with
curl_setopt(CURLOPT_RETURNTRANSFER, 1);
due to version bugginess perhaps,
you may can use output control functions
like this to show a web page
inside your webpage:
<html><head><title>whatever</title></head>
<body>
<script language="php">
$ch = curl_init("http://www.cocoavillage.com/");
ob_start();
curl_exec($ch);
curl_close($ch);
$retrievedhtml = ob_get_contents();
ob_end_clean();
$bodyandend = stristr($retrievedhtml,"<body");
$positionendstartbodytag = strpos($bodyandend,">") + 1;
$temptofindposition=strtolower($bodyandend);
$positionendendbodytag=strpos($temptofindposition,"</body");
$grabbedbody=substr($bodyandend,
$positionendstartbodytag,
$positionendendbodytag);
print("$grabbedbody");
</script>
</body></html>
tada
sharky at im dot net dot ua
22-Nov-2001 05:08
If You want to hide result which return curl_exec
Use bufeered output.
For example:
-----------------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://url.com/index.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "a=3&b=5");
//--- Start buffering
ob_start();
curl_exec ($ch);
//--- End buffering and clean output
ob_end_clean();
curl_close ($ch);
------------------
maybe it help somebody :))
----------
Best Regards
Sharky
csaba at alum dot mit dot edu
22-May-2001 01:06
If you retrieve a web page and print it (so you can see it in your browser), and the page has an expiration, this expiration now applies to MyProgram.php and next time your program/page is called, even if it's grabbing a different web page, it will show what it just displayed. In Netscape you can get rid of this by going into Edit, Options, Advanced, Cache, and clear out the Disk Cache. But this is really annoying after short order. The following prevents the above scenario:
<?php
function GetCurlPage ($pageSpec) {
$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$tmp = curl_exec ($ch);
curl_close ($ch);
$tmp = preg_replace('/(?s)<meta http-equiv="Expires"[^>]*>/i', '', $tmp);
return $tmp;
}
?>
| |