unset($client_sockets[$key]); } else { $input = trim($input); if (!@socket_write($client, "You said: {$input}\n")) { socket_close($client); unset($client_sockets[$key]); } } if ($input == 'exit') { socket_shutdown($master); $abort = true; } } // END IF in_array } // END FOREACH send_Message($client_sockets, $master, $input_f); } // END IF ($num_changed) $read = $client_sockets; $read[] = $master; } // END WHILE function send_Message($allclient, $socket, $buf) { echo 'sending message to ' . count($allclient) . " clients: \n"; $msg = "<mbFeed>{$buf}</mbFeed>\n"; foreach ($allclient as $client) { socket_write($client, $msg, 1024); } }
continue; } else { array_push($read_sockets, $client); } } else { // socket_recv just receives data from $socket as $buffer, with an integer length of 2048, and a mystery flag set to 0 // that mystery flag has no real documentation so setting it to 0 will solve it as others have done. // we've also set it as a var $bytes in case we need to ensure data sending with socket_write, which is optional $bytes = socket_recv($socket, $buffer, 2048, 0); // if the $bytes we have is 0, then it is a disconnect message from the socket // we will just search for it as an index and unset that socket from our $read_sockets and // finish up with using socket_close to ensure it is closed off if ($bytes == 0) { $index = array_search($socket, $read_sockets); unset($read_sockets[$index]); socket_close($socket); } else { // we need to make sure $read_sockets isn't messed with, so setting up a new variable called $allclients // will ensure this. We then shift the array so that our $master socket is not included to the count when // we send our data to all the other sockets in $allclients. $allclients = $read_sockets; array_shift($allclients); // just a simple call on our premade function 'send_Message' with $allclients, $socket (current one), and $buffer (the message) send_Message($allclients, $socket, $buffer); } } } if (time() - DAEMON_STARTED >= SERVER_RESTART_EVERY) { exit; } }
if (!empty($rate) && $rate < 76 && $item->{"Availability"} != "Sold Out" && !empty($info->{'LegoID'})) { $ret = publish_SaleMessage("toysrus.com", $ToysrusID, $price, $info->{'LegoID'}); if (!$ret->{'Status'}) { echo "[Info][" . date('Y-m-d H:i:s') . "] " . $info->{'LegoID'} . " on sale for \$" . $price . " (" . $rate . "% off from reg. \$" . $info->{'MSRP'} . ") www.toysrus.com/product/index.jsp?productId=" . $ToysrusID . "\n"; } else { echo "[Warning][" . date('Y-m-d H:i:s') . "] Failed to publish tweet due to " . $ret->{'Message'} . ": " . $info->{'LegoID'} . " on sale for \$" . $price . " (" . $rate . "% off from reg. \$" . $info->{'MSRP'} . ")\n"; } } } elseif (!empty($item->{'LegoID'})) { $legoID = $item->{'LegoID'}; db_insert("Toysrus_Item", array("LegoID" => $legoID, "ToysrusID" => $ToysrusID), null, true); echo "[Info][" . date('Y-m-d H:i:s') . "] New item added by legoid: " . $legoID . " - " . $item->{'Title'} . " www.toysrus.com/product/index.jsp?productId=" . $ToysrusID . "\n"; send_Message(NOTIFICATION_RECIPIENT, "New Toysrus_Item " . $legoID . " - " . $item->{'Title'} . " listed on www.toysrus.com/product/index.jsp?productId=" . $ToysrusID); } else { // try to match the legoid by title. $ret = search_legoid(array("Title" => $item->{'Title'})); if (isset($ret->{'MatchID'})) { $legoID = $ret->{'MatchID'}; db_insert("Toysrus_Item", array("LegoID" => $legoID, "ToysrusID" => $ToysrusID), null, true); } else { $legoID = null; db_insert("Toysrus_Item", array("LegoID" => "", "ToysrusID" => $ToysrusID), null, true); } echo "[Info][" . date('Y-m-d H:i:s') . "] New item added by title: " . $legoID . " - " . $item->{'Title'} . " www.toysrus.com/product/index.jsp?productId=" . $ToysrusID . "\n"; send_Message(NOTIFICATION_RECIPIENT, "New Toysrus_Item " . $legoID . " - " . $item->{'Title'} . " listed on www.toysrus.com/product/index.jsp?productId=" . $ToysrusID); } } if (!empty($arrNoupdate)) { $ret = db_update("Toysrus_Item", array("LastUpdateTime" => gmdate('Y-m-d H:i:s')), "ToysrusID IN (" . implode(",", $arrNoupdate) . ")"); echo "[Info][" . date('Y-m-d H:i:s') . "] No update for " . count($arrNoupdate) . " items\n"; }
if (!empty($rate) && $rate < 76 && ($item->{"Availability"} == "Pickup Only" || $item->{"Availability"} == "Available") && !empty($info->{'LegoID'})) { $ret = publish_SaleMessage("amazon.com", $ASIN, $price, $info->{'LegoID'}); if (!$ret->{'Status'}) { echo "[Info][" . date('Y-m-d H:i:s') . "] " . $info->{'LegoID'} . " on sale for \$" . $price . " (" . $rate . "% off from reg. \$" . $info->{'MSRP'} . ") on www.amazon.com/gp/product/" . $ASIN . "\n"; } else { echo "[Warning][" . date('Y-m-d H:i:s') . "] Failed to publish tweet due to " . $ret->{'Message'} . ": " . $info->{'LegoID'} . " on sale for \$" . $price . " (" . $rate . "% off from reg. \$" . $info->{'MSRP'} . ")\n"; } } } elseif (!empty($item->{'LegoID'})) { $legoID = $item->{'LegoID'}; db_insert("Amazon_Item", array("LegoID" => $legoID, "ASIN" => $ASIN), null, true); echo "[Info][" . date('Y-m-d H:i:s') . "] New item added by legoid: " . $legoID . " - " . $item->{'Title'} . " www.amazon.com/gp/product/" . $ASIN . "\n"; send_Message(NOTIFICATION_RECIPIENT, "New Amazon_Item " . $legoID . " - " . $item->{'Title'} . " listed on www.amazon.com/gp/product/" . $ASIN); } else { // try to match the legoid by title. $ret = search_legoid(array("Title" => $item->{'Title'})); if (isset($ret->{'MatchID'})) { $legoID = $ret->{'MatchID'}; db_insert("Amazon_Item", array("LegoID" => $legoID, "ASIN" => $ASIN), null, true); } else { $legoID = null; db_insert("Amazon_Item", array("LegoID" => "", "ASIN" => $ASIN), null, true); } echo "[Info][" . date('Y-m-d H:i:s') . "] New item added by title: " . $legoID . " - " . $item->{'Title'} . " www.amazon.com/gp/product/" . $ASIN . "\n"; send_Message(NOTIFICATION_RECIPIENT, "New Amazon_Item " . $legoID . " - " . $item->{'Title'} . " listed on www.amazon.com/gp/product/" . $ASIN); } } if (!empty($arrNoupdate)) { $ret = db_update("Amazon_Item", array("LastUpdateTime" => gmdate('Y-m-d H:i:s')), "ASIN IN (" . implode(",", $arrNoupdate) . ")"); echo "[Info][" . date('Y-m-d H:i:s') . "] No update for " . count($arrNoupdate) . " items\n"; }
$arrfields["Provider"] = $newsResult->{'Provider'}; $arrfields["Type"] = $newsResult->{'Type'}; $arrProp = array("Hash", "Title", "Link", "PicPath", "Publish", "Review"); foreach ($arrProp as $prop) { $arrfields[$prop] = $news->{$prop}; } $arrfields["PubDate"] = gmdate('Y-m-d H:i:s', $news->{'PubDate'}); $ret = db_insert("Twitter_News", $arrfields, null, true); if ($news->{'Publish'} == true && $news->{'Review'} == false) { //publish directly add_news_tweet_pool($news); } elseif ($news->{'Publish'} == true && $news->{'Review'} == true) { //send review notification $mesg = "News pending on review: " . date('Y-m-d H:i:s', $news->{'PubDate'}) . "(" . $news->{'PubDate'} . ")[" . $news->{'Hash'} . "] " . $news->{'Title'}; echo "[" . date('Y-m-d H:i:s') . "] " . $mesg . "\n"; send_Message(NOTIFICATION_RECIPIENT, $mesg . " http://www.lelemeng.com/review.php?id=" . $news->{'Hash'}); } } elseif ($NewsHash["{$hash}"] == "Y") { add_news_tweet_pool($news); } } } } function define_source() { $newsSources = array(); $source = new stdClass(); $source->{'Provider'} = "TheBrothersBrick"; $source->{'Url'} = "http://feeds.feedburner.com/TheBrothersBrick"; $source->{'Type'} = "News-RSS"; array_push($newsSources, $source);
} else { $arrfields['ThemeID'] = 0; } } } $arrProp = array("USPrice", "Year", "Pieces", "Minifigs", "Age", "Weight", "Length", "Width", "Height", "UPC", "EAN", "USItemSN", "EUItemSN"); foreach ($arrProp as $prop) { if (!empty($bkinfo->{$prop}) && $bkinfo->{$prop} != $item->{$prop}) { $arrfields[$prop] = $bkinfo->{$prop}; } } $arrfields['LastSync'] = date('Y-m-d H:i:s'); $ret = db_update("DB_Set", $arrfields, array("LegoID" => $item->{'LegoID'})); if (count($arrfields) > 1 || $ret->{'Status'}) { echo $ret->{'Query'} . "\n"; unset($arrfields['LastSync']); $strupdate = ""; foreach ($arrfields as $prop => $value) { $strupdate .= $prop . "[" . $item->{$prop} . "=>" . $value . "], "; } $strupdate = trim($strupdate, ", "); send_Message(NOTIFICATION_RECIPIENT, "DB_Set updated: " . $item->{'LegoID'} . " " . $strupdate); } } } } else { var_dump($ret); } } else { var_dump($ret); }
} //generate the csv echo $item->{'LegoID'} . ",\"" . $item->{'Availability'} . "\"," . $price . "," . $salePrice . ",\"" . $item->{'Title'} . "\"\n"; //update DB_Set if (isset($LegoDB[$item->{'LegoID'}])) { $dbitem = $LegoDB[$item->{'LegoID'}]; $arrfields = array(); if ($price > 0 && $dbitem->{'USPrice'} != $price) { $arrfields['USPrice'] = $item->{'Price'}; } if ($item->{'Title'} != $dbitem->{'ETitle'}) { $arrfields['ETitle'] = $item->{'Title'}; } if ($dbitem->{'Availability'} != $item->{'Availability'}) { $arrfields['Availability'] = $item->{'Availability'}; if (!empty($dbitem->{'Badge'}) && $dbitem->{'Badge'} != "New") { send_Message(NOTIFICATION_RECIPIENT, $item->{'LegoID'} . " - " . $item->{'Title'} . " (" . $dbitem->{'Badge'} . "): Availability changed from '" . $dbitem->{'Availability'} . "' to '" . $item->{'Availability'} . "' " . $item->{'URL'}); } } if ($dbitem->{'Badge'} != $item->{'Badge'}) { $arrfields['Badge'] = $item->{'Badge'}; } if (count($arrfields)) { update_DBSet(array("LegoID" => $item->{'LegoID'}), $arrfields); } } else { send_Message(NOTIFICATION_RECIPIENT, "New item listed on Official Lego Shop: " . $item->{'LegoID'} . " - " . $item->{'Title'} . " at \$" . $item->{'Price'} . " " . $item->{'URL'}); new_tweet("New item listed on Official Lego Shop: " . $item->{'LegoID'} . " - " . $item->{'Title'} . " at \$" . $item->{'Price'} . " " . $item->{'URL'}); insert_DBSet(array("LegoID" => $item->{'LegoID'}, "ETitle" => $item->{'Title'}, "USPrice" => $item->{'Price'}, "Badge" => $item->{'Badge'})); } }
$ret = publish_SaleMessage("walmart.com", $walmartID, $price, $info->{'LegoID'}); var_dump($ret->{'Message'}); if (!$ret->{'Status'}) { echo "[Info][" . date('Y-m-d H:i:s') . "] " . $info->{'LegoID'} . " on sale for \$" . $price . " (" . $rate . "% off from reg. \$" . $info->{'MSRP'} . ") www.walmart.com/ip/" . $walmartID . "\n"; } else { echo "[Warning][" . date('Y-m-d H:i:s') . "] Failed to publish tweet due to " . $ret->{'Message'} . ": " . $info->{'LegoID'} . " on sale for \$" . $price . " (" . $rate . "% off from reg. \$" . $info->{'MSRP'} . ")\n"; } } } elseif (!empty($item->{'LegoID'})) { $legoID = $item->{'LegoID'}; db_insert("Walmart_Item", array("LegoID" => $legoID, "WalmartID" => $walmartID), null, true); echo "[Info][" . date('Y-m-d H:i:s') . "] New item added by legoid: " . $legoID . " - " . $item->{'Title'} . " www.walmart.com/ip/" . $walmartID . " \n"; send_Message(NOTIFICATION_RECIPIENT, "New Walmart_Item " . $legoID . " - " . $item->{'Title'} . " listed on www.walmart.com/ip/" . $walmartID); } else { // try to match the legoid by title. $ret = search_legoid(array("Title" => $item->{'Title'})); if (isset($ret->{'MatchID'})) { $legoID = $ret->{'MatchID'}; db_insert("Walmart_Item", array("LegoID" => $legoID, "WalmartID" => $walmartID), null, true); } else { $legoID = null; db_insert("Walmart_Item", array("LegoID" => "", "WalmartID" => $walmartID), null, true); } echo "[Info][" . date('Y-m-d H:i:s') . "] New item added by title: " . $legoID . " - " . $item->{'Title'} . " www.walmart.com/ip/" . $walmartID . " \n"; send_Message(NOTIFICATION_RECIPIENT, "New Walmart_Item " . $legoID . " - " . $item->{'Title'} . " listed on www.walmart.com/ip/" . $walmartID); } } if (!empty($arrNoupdate)) { $ret = db_update("Walmart_Item", array("LastUpdateTime" => gmdate('Y-m-d H:i:s')), "WalmartID IN (" . implode(",", $arrNoupdate) . ")"); echo "[Info][" . date('Y-m-d H:i:s') . "] No update for " . count($arrNoupdate) . " items\n"; }