Deprecated: Creation of dynamic property SyntaxHighlighter::$brush_names is deprecated in /web/htdocs/ on line 248

Deprecated: Creation of dynamic property SyntaxHighlighter::$specialchars is deprecated in /web/htdocs/ on line 326
Ping services with PHP

Ping services with PHP

Ping-o-matic is a service that calls (ping) server engines and popular services to notify them that you have new contents…

Febbraio 24, 2010

Ping-o-matic is a service that calls (ping) server engines and popular services to notify them that you have new contents on your site. This will help you to get your pages indexed on that servers and so it should increase your traffic.
I don’t know if this system works, but it’s implemented also in any wordpress installation, so telling Ping-o-matic that you have new contents should be a good thing. :-)
I’ve searched the web for a function to do this with php, but I didn’t found it and I’ve decided to write it by myself.

Ping-o-matic as many other services works with XML-RPC protocol, the acronym means XML Remote Procedure Call. That is to say that you can call some servers and tell them to execute some action remotely. In this case we use XML-RPC protocol to call Ping-o-matic and tell him: “EHY! I’ve updated my site, here is the link!“.
Ping-o-matic take this link and send it to many other popular services.

The complex part, for me, was understing XML-RPC rules and build the correct headers to call the service. The call is made with fsockopen php function. Here is the function that will be added to the next version of Mini Bot Class.

 $title contains the title of the page you're sending
 $url is the url of the page
 $debug true print out the debug and show xml call and answer
 the output is an array with two elements:
 status: ok / ko
 msg: the text response from pingomatic
function pingomatic($title,$url,$debug=false) {
	$content='<?xml version="1.0"?>'.
		' <methodName></methodName>'.
		'  <params>'.
		'   <param>'.
		'    <value>'.$title.'</value>'.
		'   </param>'.
		'  <param>'.
		'   <value>'.$url.'</value>'.
		'  </param>'.
		' </params>'.

	$headers="POST / HTTP/1.0\r\n".
	"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)\r\n".
	"Content-Type: text/xml\r\n".
	"Content-length: ".strlen($content);

	if ($debug) nl2br($headers);

	$response = "";
	$fs=fsockopen('',80, $errno, $errstr);
	if ($fs) { 
		fwrite ($fs, $request); 
		while (!feof($fs)) $response .= fgets($fs); 
		if ($debug) echo "<xmp>".$response."</xmp>";
		fclose ($fs);
		preg_match_all("/<(name|value|boolean|string)>(.*)<\/(name|value|boolean|string)>/U",$response,$ar, PREG_PATTERN_ORDER);
		for($i=0;$i<count($ar[2]);$i++) $ar[2][$i]= strip_tags($ar[2][$i]);
		return array('status'=> ( $ar[2][1]==1 ? 'ko' : 'ok' ), 'msg'=>$ar[2][3] );
	} else { 
		if ($debug) echo "<xmp>".$errstr." (".$errno.")</xmp>"; 
		return array('status'=>'ko', 'msg'=>$errstr." (".$errno.")");


PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “Ping services with PHP”

34 thoughts

  1. Haber Pan ha detto:

    This function is working succesfull.
    Thank you my brother.

  2. JDG ha detto:

    Appreciate the script!

  3. Aiko ha detto:

    Implemented this script in my blog to ping with every new post.
    It works like a charm !!

    Thank you for sharing this code!

  4. Aiko ha detto:

    Made some small changes (pingomatic to feedburner) and now the script pings feedburner as well.
    Guess it can be used for more services.

    It’s a great script. I made a blogpost about this at . It’s in Dutch so you might gain some fame in the Netherlands :-)

    Thanks again!

  5. admin ha detto:

    I’ve read your post with google translate, thanks!

  6. steven ha detto:

    yeah! it works! I even had it converted using curl… :)
    btw there’s a little question i had in mind about the return xml from pingomatic…
    when the ping is successful, pingomatic replied with xml which contain “Pings being forwarded to 13 services!”…what I have no idea with is the 13 services.. what services exactly those 13 really are? I’ve been searching the internet about that but no luck..
    Do you know what it is? or anyone know?

    thanks & regards,

  7. Andrew ha detto:

    Hello!Thanks a lot for this amazing script.I just have some questions.. because I cannot make it run.Does this script work with any website?Could you please provide some install instructions because I don’t have too many knowledges about php.Where to add the title and the url?Thank you!!!

  8. outsource ha detto:

    It works fine for me, tried it with XML RPC for IceRocket and it’s working as well

  9. M. Singh ha detto:

    Will it automatically publish content to pingomatic, Whenever a new post is published?
    Or we have to run this script everytime.

  10. Orkiestry weselne ha detto:

    For me the best SEO script ever made :)

    Who is green guy down?

  11. andi ha detto:

    finally.. 2 years ago, i was searching some methods to ping for my blog script, but i didn’t find it and i stop my own php blog project,, but now, there’s a hope to rebuild my script.. thanks dude… :D

  12. Shaaam ha detto:

    Finally i get the solution, this is good script and works fine for me. Now i can tweet and ping both.

  13. Udin ha detto:

    I have implemented your script, how to make sure that this script is working well in my site ? thanks for the explanation

  14. tech ha detto:

    nice script, very nice.

    Thanks for sharing

  15. Fab Articles ha detto:

    Awesome script, cheers dude – saved me a lot of time and effort lol :) x

  16. Thank you so much for this. Saved me a lot of coding time. Much appreciated.

  17. Noticias online ha detto:

    Do you know if this works with other ping sites ?

  18. dowcipy ha detto:

    this is very helpful for me. Thank you.

  19. oom ha detto:

    thanks for sharing, but.. can you show me for demo use this script? thanks before

  20. yuliang ha detto:

    just a question, can u ping other services as well?

  21. Sabine ha detto:

    how can use the script?
    only with linux or windws? thanks

  22. Hung Nguyen ha detto:

    Sorry mate,
    Run your script but get error: Array ( [flerror] => [message] => Pings being forwarded to 11 services! )
    I dont know success or failure :(

  23. Giulio Pons ha detto:

    That message it’s an ok messagge! :-)

  24. konya haber ha detto:

    thanks for great code.


  25. shahid ha detto:

    I have about 40000 posts in my wordpress and want to use this script in a loop that sends the title and the url of the page to pingomatic.

    Would this be a stupid thing to do? I am new to coding and SEO so pardon my ignorance.

  26. i still need more information about that

  27. Xavier ha detto:

    What I will say is very simple but true: thank you! Your code has saved much time in my research.

  28. Bryan ha detto:

    thank you Guilio. thanks for sharing

  29. SKIFF ha detto:

    Thanks. It’s really needed script for me in my work-hobby)) Gook luck!

  30. Bryan ha detto:

    Thanks for the script, it worked flawlessly by just plugging in the URL and Title, :).

    I’ll be adapting it for my project though to allow it to ping multiple sites instead of just the one, but this was perfect for giving a framework.

  31. BabyWolf ha detto:

    Thanks for script! I have just included this to my company website. I hope my content will be faster indexed by SE.

  32. viettq ha detto:

    Run your script use function pingomatic($title,$url,true) this get me:

    HTTP/1.1 200 OK Server: nginx Date: Thu, 08 Nov 2012 07:36:54 GMT Content-Type: text/xml;charset=utf-8 Content-Length: 344 Connection: close flerror0 messagePings being forwarded to 9 services!

    [status] => ok
    [msg] => Pings being forwarded to 9 services!

    but I can not find my result as Ping live from on the how can i know your script has worked?

  33. morzak ha detto:

    this is very helpful for me.

Comments are closed


Twitter counter no longer works

Since 20 of November 2015 the twitter button has changed. This is the new Twitter sharing button, as you can…

Novembre 23, 2015

Get instagram data without official api in PHP

Instagram has an official API to interact with its database of images and users. If you have enough time to…

Dicembre 3, 2013

PHP bot to get wikipedia definitions

Wikipedia, the collaborative and multilingual encyclopedia project, has a lot of usefull terms defined in its database, you can find…

Agosto 29, 2010

Send push notification to iPhone with PHP and

UPDATE: 2013/11/18 This code no longer works, but you can check a similar function here: Sending push notifications with php…

Agosto 9, 2010

PHP google images mini bot

UPDATE 2013/12/12: Now, in the  Mini Bot Class there is a version of this function that is still working. You…

Marzo 30, 2010

Find values recursively inside complex json objects in PHP

A PHP function to to quickly search complex, nested php structures for specific values.

Dicembre 18, 2022