-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathPing.php
69 lines (63 loc) · 1.28 KB
/
Ping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Melbahja\Seo;
use Melbahja\Seo\Interfaces\SeoInterface;
/**
* @package Melbahja\Seo
* @since v2.0
* @see https://git.io/phpseo
* @license MIT
* @copyright 2019-present Mohamed Elabhja
*/
class Ping implements SeoInterface
{
/**
* Engines to inform
* @var array
*/
protected $engines =
[
'https://www.google.com',
'https://www.bing.com',
'https://webmaster.yandex.com'
];
/**
* Initialize new sitemap bing
*
* @param array $append
*/
public function __construct(array $append = [])
{
if (empty($append) === false) {
$this->engines = array_unique(array_merge($this->engines, $append));
}
}
/**
* Send sitemap url to registred engines
*
* @param string $sitemapUrl
* @return void
*/
public function send(string $sitemapUrl): void
{
foreach ($this->engines as $engine)
{
$this->inform($engine, $sitemapUrl);
}
}
/**
* Inform search engine
*
* @param string $engine
* @param string $url
* @return void
*/
public function inform(string $engine, string $url): void
{
$req = curl_init("{$engine}/ping?sitemap={$url}");
curl_setopt($req, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
curl_exec($req);
curl_close($req);
}
}