curl_close

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

curl_closecURL oturumunu sonlandırır

Açıklama

curl_close(CurlHandle $tanıtıcı): void

Bilginize:

Bu işlevin bir etkisi yoktur. PHP 8.0.0 öncesinde, bu işev özkaynağı kapatmak için kullanılırdı.

cURL oturumunu sonlandırır ve ayrılmış özkaynakları serbest bırakır. Ayrıca, cURL tanıtıcısı tanıtıcı silinir.

Bağımsız Değişkenler

tanıtıcı

curl_init() işlevinden dönen bir cURL tanıtıcısı.

Dönen Değerler

Hiçbir değer dönmez.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0tanıtıcı için artık bir CurlHandle örneği bekleniyor; evvelce, resource türünde bir değer beklenirdi.

Örnekler

Örnek 1 - Yeni bir cURL oturumunun ilklendirilmesi ve bir HTML sayfasının alınması

<?php
// Yeni bir cURL tanıtıcısı oluşturalım
$ct = curl_init();

// URL'yi ve ilgili seçenekleri belirleyelim
curl_setopt($ct, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ct, CURLOPT_HEADER, 0);

// URL'yi tarayıcıya aktaralım
curl_exec($ct);

// cURL tanıtıcısını kapatıp sistem özkaynaklarını serbest bırakalım
curl_close($ct);
?>

Ayrıca Bakınız

add a note

User Contributed Notes 4 notes

up
0
naglpaul417 at gmail dot com
44 minutes ago
<?php
$servername
= "localhost";
$username = "root";
$password = "";

try {
$conn = new PDO("mysql:host=$servername;dbname=crud_project", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(
PDOException $e) {
echo
"Connection failed: " . $e->getMessage();
}

if(isset(
$_POST['add'])){
$newTitle = $_POST['title'];
$newContent = $_POST['content'];
$stmt = $conn->prepare("INSERT INTO entries (user_id, title, content) VALUES (1, '$newTitle', '$newContent')");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

if(isset(
$_POST['delete'])){
$delete_id = $_POST['delete'];
$stmt = $conn->prepare("DELETE FROM entries WHERE id = ?");
$stmt->execute([$delete_id]);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

if(isset(
$_POST['update']) && isset($_POST['title']) && isset($_POST['content'])){
$stmt = $conn->prepare("UPDATE entries SET title = ?, content = ? WHERE id = ?");
$stmt->execute([$_POST['title'], $_POST['content'], $_GET['edit']]);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Uebung</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">user_id</th>
<th scope="col">title</th>
<th scope="col">content</th>
<th scope="col">created_at</th>
<th scope="col">options</th>
</tr>
</thead>
<tbody>
<?php
$stmt
= $conn->prepare("SELECT * FROM entries");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach (
$result as $row) {
echo
"<tr>";
foreach (
$row as $value) {
echo
"<td>" . $value . "</td>";
}
echo
"<form method='get'>";
echo
"<td><button class='btn btn-primary' name='edit' value='" . $row['id'] . "'> Details </button></td>";
echo
"</form>";
echo
"<form method='post'>";
echo
"<td><button class='btn btn-danger' name='delete' value='" . $row['id'] . "'> Delete </button></td>";
echo
"</form>";
echo
"</tr>";
}
?>
up
0
naglpaul417 at gmail dot com
44 minutes ago
</tbody>
</table>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Add
</button>

<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Modal title</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="post">
<div class="modal-body">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Title</label>
<input type="text" class="form-control" aria-describedby="emailHelp" id="title" name="title">
<div id="emailHelp" class="form-text">Your title here...</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Content</label>
<input type="text" class="form-control" id="content" name="content">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" name="add" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">user_id</th>
<th scope="col">title</th>
<th scope="col">content</th>
<th scope="col">created_at</th>
<th scope="col">options</th>
</tr>
</thead>
<tbody>
up
0
naglpaul417 at gmail dot com
46 minutes ago
<?php
if(isset($_GET['edit'])){
$edit_id = $_GET['edit'];
$stmt = $conn->prepare('SELECT * FROM entries WHERE id = ?');
$stmt->execute([$edit_id]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach (
$results as $row) {
echo
"<tr>";
foreach (
$row as $value) {
echo
"<td>" . $value . "</td>";
}
echo
"<td><button type='button' class='btn btn-primary' data-bs-toggle='modal' data-bs-target='#exampleModal2'> Update </button></td> ";
echo
"</tr>";
$title = $row['title'];
$content = $row['content'];
}
}
?>

<div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Modal title</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form method="post">
<div class="modal-body">
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Title</label>
<input type="text" class="form-control" aria-describedby="emailHelp" id="title" name="title" value="<?php echo $title; ?>">
<div id="emailHelp" class="form-text">Your title here...</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Content</label>
<input type="text" class="form-control" id="content" name="content" value="<?php echo $content; ?>">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" name="update" class="btn btn-primary">Update</button>
</div>
</form>
</div>
</div>
</div>
</tbody>
</table>
<div>
</div>
</div>
</body>
</html>
up
-2
JS
1 year ago
Although the Note for this call says "Prior to PHP 8.0.0, this function was used to close the resource", I found that PHP 7.4.33 on CentOS is not closing the connection on curl_close.

The workaround if you want to make sure the connection closes immediately after the request is to set the curl option to forbid reuse:

curl_setopt($curl, CURLOPT_FORBID_REUSE, TRUE);
To Top