I gang

Fix Social Sharing PHP Process

We currently have a social sharing script running on our site which allows visitors to share our content on facebook, twitter and google plus. However, the script is overloading our server (facebook share count specifically) as per the hosting provider. The developer of the script has implemented a session close loop for facebook which was believed to be causing the issue but the issue has re-emerged. After speaking to our hosting provider, they told us that the facebook sharing php script is causing a large number of connections to come from a facebook related ip. We need this fixed as soon as possible. Here is the current php script below:

<?php

class shareCount {

private $url,$timeout;

function __construct($url,$timeout=10) {

$this->url=rawurlencode($url);

$this->timeout=$timeout;

}

function get_tweets() {

$json_string = $this->file_get_contents_curl('[url removed, login to view]' . $this->url);

$json = json_decode($json_string, true);

return isset($json['count'])?intval($json['count']):0;

}

function get_fb() {

$json_string = $this->file_get_contents_curl('[url removed, login to view]'.$this->url);

$json = json_decode($json_string, true);

return isset($json[0]['total_count'])?intval($json[0]['total_count']):0;

}

function get_plusones() {

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "[url removed, login to view]");

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"[url removed, login to view]","id":"p","params":{"nolog":true,"id":"'.rawurldecode($this->url).'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));

$curl_results = curl_exec ($curl);

curl_close ($curl);

$json = json_decode($curl_results, true);

return isset($json[0]['result']['metadata']['globalCounts']['count'])?intval( $json[0]['result']['metadata']['globalCounts']['count'] ):0;

}

function get_pinterest() {

$return_data = $this->file_get_contents_curl('[url removed, login to view]'.$this->url);

$json_string = preg_replace('/^receiveCount\((.*)\)$/', "\\1", $return_data);

$json = json_decode($json_string, true);

return isset($json['count'])?intval($json['count']):0;

}

private function file_get_contents_curl($url){

$ch=curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

curl_setopt($ch, CURLOPT_FAILONERROR, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);

$cont = curl_exec($ch);

if(curl_error($ch))

{

die(curl_error($ch));

}

return $cont;

curl_close($ch);

}

}

?>

Færdigheder: Apache, PHP, Software Arkitektur

Se mere: pinterest api php, curl software, sharing content, php pos, nolog, jsonrpc, google ch, api pos, facebook share url, curl loop, api viewer, pinterest software architecture, google plus developer, facebook share content, loop json, twitter json, curl developer, developer curl, pinterest share, twitter developer api key, pinterest share api, php api session, curl pinterest, url pinterest, php api json server

Om arbejdsgiveren:
( 5 bedømmelser ) toronto, Canada

Projekt-ID: #5981092

Tildelt til:

peterkurt

Hi, there are two possible solutions: 1)store this data to memcached 2)if your webhost don't have memcached store it to files and load it for example once in 30minutes it's possible to store it permanently and l Mere

$25 USD på 1 dag
(3 bedømmelser)
2.4

3 freelancere byder i gennemsnit $28 for dette job

voomes

A proposal has not yet been provided

$25 USD på 1 dag
(22 bedømmelser)
4.4
bidtechnologies

Hi From the code that appears , i find you need to use elite proxies/socks to connect to facebook via CURL. This will fix the problem. Thanks Ken

$35 USD in 3 dage
(3 bedømmelser)
2.5