3v4l.org

run code in 300+ PHP versions simultaneously
<?php $now = date('Y-m-d h:20'); $today = date('Y-m-d'); $afternoon = date('Y-m-d 17:27'); // require Facebook PHP SDK // see: https://developers.facebook.com/docs/php/gettingstarted/ require_once("sdk/facebook.php"); // initialize Facebook class using your own Facebook App credentials // see: https://developers.facebook.com/docs/php/gettingstarted/#install $config = array(); $config['appId'] = '290692250950652'; // configure appropriately $config['secret'] = 'b796627dc623cee90ac49ac806d6b4e8'; // configure appropriately $config['fileUpload'] = false; // optional $fb = new Facebook($config); $user_id="1740048734"; $page_id="127287113972280"; $group_id="115454235207375"; $user_token = array(); $page_token = array(); $user_token['access_token'] = 'CAAEIYhBbWZCwBAEkHQxFNWkdVY52PGapKqccqQX2QlLHM2pqZB1dR7oumasYUhCkAZCW95Ab4f3HmzpPygWXkrHk0fl1t1iaGlfyaCjG04B8shEx3Bp3VzVakM5xZAFBUOLZB3T8TirYWwAGrZBrAEexymrA5YXGYMFgipex0Ho1kmt3BWdhVebcU2GLPJBiMZD'; $fb->setAccessToken($user_token['access_token']); $accounts = $fb->api('/'.$user_id.'/accounts'); foreach($accounts['data'] as $account){ if($account['id'] == $page_id){ $page_token['access_token'] = $account['access_token']; } } $conn = new mysqli("localhost", "mvawzuyw_admin", "#veyron_153", "mvawzuyw_sharecenter"); if ($conn->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } // create array with topics to be posted on Facebook $sql = 'SELECT * FROM queue WHERE date IS NOT NULL AND count > 0 ORDER BY date ASC'; $rs = $conn->query($sql); if($rs === false) { $user_error = 'Wrong SQL: ' . $sql . '<br>' . 'Error: ' . $conn->errno . ' ' . $conn->error; trigger_error($user_error, E_USER_ERROR); } $rs->data_seek(0); $share_topics = array(); while($res = $rs->fetch_assoc()) { $a_topic = array( "url" => $res["url"], "title" => $res["title"], "message" => $res["message"], "description" => $res["description"], "image" => $res["image"], "targets" => $res["targets"], "event_date" => $res["event_date"], "photo" => $res["photo"], "count" => $res["count"], "date" => $res["date"] ); array_push($share_topics, $a_topic); } $rs->free(); foreach($share_topics as $share_topic) { if($share_topic['date'] == $now ) { // define POST parameters $content = array( "message" => $share_topic["message"], "link" => $share_topic["url"], "name" => $share_topic["title"], "caption" => "https://sekazone.ro", // configure appropriately "description" => $share_topic["description"] ); try { $ret = $fb->api('/'.$page_id.'/feed', 'POST', array_merge($page_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(10); try { $ret = $fb->api('/'.$user_id.'/feed', 'POST', array_merge($user_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(10); try { $ret = $fb->api('/'.$group_id.'/feed', 'POST', array_merge($user_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(10); foreach ($share_topic['targets'] as $value) { try { $ret = $fb->api('/'.$value.'/feed', 'POST', array_merge($user_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(25); } $share_topic["count"] = $share_topic["count"] -1; $sql = 'UPDATE queue SET count = '.$share_topic['count'].' WHERE url = ' . $share_topic['url']; if($conn->query($sql) === false) : trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR); endif; // IS TODAY __________________________________________________________________ } elseif ($share_topic['event_date'] == $today && $now == $afternoon) { $content = array( "message" => $share_topic["message"], "link" => $share_topic["url"], "name" => $share_topic["title"], "caption" => "https://sekazone.ro", // configure appropriately "description" => $share_topic["description"] ); try { $ret = $fb->api('/'.$page_id.'/feed', 'POST', array_merge($page_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(10); try { $ret = $fb->api('/'.$user_id.'/feed', 'POST', array_merge($user_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(10); try { $ret = $fb->api('/'.$group_id.'/feed', 'POST', array_merge($user_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(10); foreach ($share_topic['targets'] as $value) { try { $ret = $fb->api('/'.$value.'/feed', 'POST', array_merge($user_token, $content)); echo 'Successfully posted to Facebook'; } catch(Exception $e) { echo $e->getMessage(); } sleep(25); } $share_topic["count"] = $share_topic["count"] -1; $sql = 'UPDATE queue SET count = '.$share_topic['count'].' WHERE url = ' . $share_topic['url']; if($conn->query($sql) === false) : trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR); endif; } } ?>

preferences:
41.02 ms | 402 KiB | 5 Q