From 514ab448cd05fb253954e2f00922779f6d32e578 Mon Sep 17 00:00:00 2001 From: Onervv Date: Thu, 12 Feb 2026 12:00:40 -0500 Subject: [PATCH 01/10] adding mysqlconnect.php template code --- README.md | 7 +++++++ mysqlconnect.php | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 README.md create mode 100644 mysqlconnect.php diff --git a/README.md b/README.md new file mode 100644 index 000000000..5196a3285 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# IT490-004 | System Integration Project + + +### Overview +Class Project to demonstrate the creation of a full stack application. + +### Build diff --git a/mysqlconnect.php b/mysqlconnect.php new file mode 100644 index 000000000..9ca5f1215 --- /dev/null +++ b/mysqlconnect.php @@ -0,0 +1,25 @@ +#!/usr/bin/php +errno != 0) +{ + echo "failed to connect to database: ". $mydb->error . PHP_EOL; + exit(0); +} + +echo "successfully connected to database".PHP_EOL; + +$query = "select * from students;"; + +$response = $mydb->query($query); +if ($mydb->errno != 0) +{ + echo "failed to execute query:".PHP_EOL; + echo __FILE__.':'.__LINE__.":error: ".$mydb->error.PHP_EOL; + exit(0); +} + + +?> \ No newline at end of file From 193734b5eb9559abf6bb999bafb933789d06f603 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Thu, 12 Mar 2026 00:14:45 -0400 Subject: [PATCH 02/10] added dmz processor and cron --- dmz-processor/cron.php | 11 +++ dmz-processor/processor.php | 182 ++++++++++++++++++++++++++++++++++++ rabbitMQLib.inc | 6 +- testRabbitMQ.ini | 23 +++++ 4 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 dmz-processor/cron.php create mode 100644 dmz-processor/processor.php diff --git a/dmz-processor/cron.php b/dmz-processor/cron.php new file mode 100644 index 000000000..f7b4cb520 --- /dev/null +++ b/dmz-processor/cron.php @@ -0,0 +1,11 @@ +#!/usr/bin/php +publish($request); diff --git a/dmz-processor/processor.php b/dmz-processor/processor.php new file mode 100644 index 000000000..95e643e20 --- /dev/null +++ b/dmz-processor/processor.php @@ -0,0 +1,182 @@ +#!/usr/bin/php + $method, + "api_key" => $api_key, + "format" => "json", ], + $extras); + + $endpoint = $url . "?" . http_build_query($query); //creates url + $data = file_get_contents($endpoint); + + return json_decode($data, true); //returns data +} + + +function top_tracks($url, $api) { //get the top tracks + echo "Top Tracks \n"; + + $data = lastfm($url, $api, "chart.getTopTracks") ; //chart.getTopTracks + + if (!$data || !isset($data["tracks"]["track"])) { //checks for error + echo "No Track Data"; + return null; + } + + $tracks = []; + foreach ($data["tracks"]["track"] as $i => $track) { //puts them into a list + $tracks[] = [ + "rank" => $i + 1, + "track_name" => $track["name"], + "artist" => $track["artist"]["name"], + "play_count" => (int)($track["playcount"] ), + "listeners" => (int)($track["listeners"] ), + "url" => $track["url"], + ]; + } + + echo "DONE \n"; + return [ //returns formatted list + "type" => "top_tracks", + "fetched_at" => date("Y-m-d"), + "payload" => $tracks + ]; +} + +function top_artists($url, $api) { //gets the top artists + echo "Top Artists \n"; + + $data = lastfm($url, $api, "chart.getTopArtists"); //chart.getTopArtists + + if (!$data || !isset($data["artists"]["artist"])) { //error checking + echo "No Artists Data \n"; + return null; + } + + $artists = []; + foreach ($data["artists"]["artist"] as $i => $artist) { //puts them into a list + $artists[] = [ + "rank" => $i + 1, + "name" => $artist["name"] ?? "", + "listeners" => (int)($artist["listeners"] ?? 0), + "play_count" => (int)($artist["playcount"] ?? 0), + ]; + } + + echo "DONE \n"; + return [ //returns formatted list + "type" => "top_artists", + "fetched_at" => date("Y-m-d"), + "payload" => $artists + ]; +} + +function artist_info($url, $api, $name) { //gets the information on a certain artist + echo "Artist Info \n"; + + $data = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //artst.getInfo + + if (!$data || !isset($data["artist"])) { //error checking + echo "No Data for Artist: $name\n"; + return null; + } + + echo "DONE \n"; + return [ //returns formatted info + "type" => "artist_info", + "fetched_at" => date("Y-m-d"), + "payload" => [ + "name" => $data["artist"]["name"] ?? "", + "listeners" => (int)($data["artist"]["stats"]["listeners"] ), + "play_count" => (int)($data["artist"]["stats"]["playcount"] ), + "bio" => trim(strip_tags($data["artist"]["bio"]["summary"] )), + "url" => $data["artist"]["url"], + ] + ]; +} + +function many_artists($url, $api) { //gets info for 300 artists + echo "300 Artists \n"; + + $data = lastfm($url, $api, "chart.getTopArtists", ["limit" => 300]); + + if (!$data || !isset($data["artists"]["artist"])) { //error checking + echo "No Artists Data \n"; + return null; + } + + $results = []; + foreach ($data["artists"]["artist"] as $artist) { //loop through each artist + $name = $artist["name"] ?? ""; + echo "Fetching: $name \n"; + + // get info for each artist + $info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); + + if (!$info || !isset($info["artist"])) { //skip if no data + echo "No data for: $name \n"; + continue; + } + + $results[] = [ + "name" => $info["artist"]["name"] ?? "", + "listeners" => (int)($info["artist"]["stats"]["listeners"] ?? 0), + "play_count" => (int)($info["artist"]["stats"]["playcount"] ?? 0), + "bio" => trim(strip_tags($info["artist"]["bio"]["summary"] ?? "")), + "url" => $info["artist"]["url"] ?? "", + ]; + } + echo "DONE \n"; + return [ + "type" => "many_artists", + "fetched_at" => date("Y-m-d"), + "payload" => $results + ]; +} + +function requests($request) { //handles the requests + global $API, $URL; + + if (!isset($request['type'])) { //error checking + return ["status" => "error", "message" => "unsupported type"]; + } + + if($request['type'] == "weekly_charts") { //calls function in charge of the weekly charts + $tracks = top_tracks($URL, $API); + $artists = top_artists($URL, $API); + return [ + "status" => "success", + "tracks" => $tracks, + "artists" => $artists]; + + } else if ($request["type"] == "artist") { //calls function in charge of artists + $name = $request["name"] ?? ""; + if ($name == "") { + return ["status" => "error", "message" => "Missing artist name."]; + } + $data = artist_info($URL, $API, $name); + return ["status" => "success", "data" => $data]; + + } else if ($request["type"] == "many_artists") { + $data = many_artists($URL, $API); + return ["status" => "success", "data" => $data]; + + } else { //error checking if the request is unknown + echo "Unknown type: " . $request['type'] . "\n"; + return ["status" => "error", "message" => "Unknown type: " . $request['type']]; + } +} +$server = new rabbitMQServer(__DIR__ . '/../testRabbitMQ.ini', 'testServer3'); //connection to the broker +echo"DMZ START\n"; +$server->process_requests('requests'); +exit(); +?> diff --git a/rabbitMQLib.inc b/rabbitMQLib.inc index 94c13c1f0..d86cb5c0f 100644 --- a/rabbitMQLib.inc +++ b/rabbitMQLib.inc @@ -34,12 +34,13 @@ class rabbitMQServer } $this->exchange = $this->machine[$server]["EXCHANGE"]; $this->queue = $this->machine[$server]["QUEUE"]; + $this->routing_key = $this->machine[$server]["ROUTING_KEY"]; } function process_message($msg) { // send the ack to clear the item from the queue - if ($msg->getRoutingKey() !== "*") + if ($msg->getRoutingKey() !== $this->routing_key) { return; } @@ -74,6 +75,7 @@ class rabbitMQServer $conn_queue = new AMQPQueue($channel); $conn_queue->setName($msg->getReplyTo()); $replykey = $this->routing_key.".response"; + $conn_queue->declare(); $conn_queue->bind($exchange->getName(),$replykey); $exchange->publish(json_encode($response),$replykey,AMQP_NOPARAM,array('correlation_id'=>$msg->getCorrelationId())); @@ -166,6 +168,7 @@ class rabbitMQClient } $this->exchange = $this->machine[$server]["EXCHANGE"]; $this->queue = $this->machine[$server]["QUEUE"]; + $this->routing_key = $this->machine[$server]["ROUTING_KEY"]; } function process_response($response) @@ -267,6 +270,7 @@ class rabbitMQClient die("failed to send message to exchange: ". $e->getMessage()."\n"); } } + } ?> diff --git a/testRabbitMQ.ini b/testRabbitMQ.ini index d63cd54f4..30b4b0ea7 100644 --- a/testRabbitMQ.ini +++ b/testRabbitMQ.ini @@ -9,3 +9,26 @@ QUEUE = testQueue ;EXCHANGE_TYPE = ???? AUTO_DELETE = true +[testServer2] +BROKER_HOST = 100.88.147.61 +BROKER_PORT = 5672 +USER = test +PASSWORD = test +VHOST = testHost +EXCHANGE = testExchange +QUEUE = testQueue +ROUTING_KEY = us.frontend +;EXCHANGE_TYPE = ???? +AUTO_DELETE = true + +[testServer3] +BROKER_HOST = 100.88.147.61 +BROKER_PORT = 5672 +USER = test +PASSWORD = test +VHOST = testHost +EXCHANGE = testExchange +QUEUE = dmz_jobs +ROUTING_KEY = us.api +;EXCHANGE_TYPE = ???? +AUTO_DELETE = true From 8a2c37dd7adad15f29633b7e1c39844eedbbc4c7 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Thu, 12 Mar 2026 00:18:21 -0400 Subject: [PATCH 03/10] fixing cron job file --- dmz-processor/cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmz-processor/cron.php b/dmz-processor/cron.php index f7b4cb520..5d8b87433 100644 --- a/dmz-processor/cron.php +++ b/dmz-processor/cron.php @@ -4,7 +4,7 @@ require_once __DIR__ . '/../get_host_info.inc'; require_once __DIR__ . '/../rabbitMQLib.inc'; -$connection = new rabbitMQClient(__DIR__ . '/../testRabbitMQ.ini', 'testServer2'); //connection to the broker +$connection = new rabbitMQClient(__DIR__ . '/../testRabbitMQ.ini', 'testServer3'); //connection to the broker $request['type']= "weekly_charts"; From 3a5354dc59d639f2b0fdf2ccaddc2ef6371b5315 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Thu, 12 Mar 2026 08:39:47 -0400 Subject: [PATCH 04/10] Update processor --- dmz-processor/processor.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/dmz-processor/processor.php b/dmz-processor/processor.php index 95e643e20..30cd82bb0 100644 --- a/dmz-processor/processor.php +++ b/dmz-processor/processor.php @@ -16,6 +16,7 @@ function lastfm($url, $api_key, $method, $extras = []) { //call api $extras); $endpoint = $url . "?" . http_build_query($query); //creates url + $data = file_get_contents($endpoint); return json_decode($data, true); //returns data @@ -80,10 +81,10 @@ function top_artists($url, $api) { //gets the top artists ]; } -function artist_info($url, $api, $name) { //gets the information on a certain artist +function artist_info($url, $api, $name) { //gets the information on an artist echo "Artist Info \n"; - $data = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //artst.getInfo + $data = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //artist.getInfo if (!$data || !isset($data["artist"])) { //error checking echo "No Data for Artist: $name\n"; @@ -117,12 +118,10 @@ function many_artists($url, $api) { //gets info for 300 artists $results = []; foreach ($data["artists"]["artist"] as $artist) { //loop through each artist $name = $artist["name"] ?? ""; - echo "Fetching: $name \n"; - // get info for each artist - $info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); + $info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //get info for each artist on the chart - if (!$info || !isset($info["artist"])) { //skip if no data + if (!$info || !isset($info["artist"])) { //skips if no data echo "No data for: $name \n"; continue; } @@ -150,7 +149,7 @@ function requests($request) { //handles the requests return ["status" => "error", "message" => "unsupported type"]; } - if($request['type'] == "weekly_charts") { //calls function in charge of the weekly charts + if($request['type'] == "weekly_charts") { //calls functions for the weekly charts $tracks = top_tracks($URL, $API); $artists = top_artists($URL, $API); return [ @@ -160,23 +159,24 @@ function requests($request) { //handles the requests } else if ($request["type"] == "artist") { //calls function in charge of artists $name = $request["name"] ?? ""; - if ($name == "") { + + if ($name == "") { //error checking return ["status" => "error", "message" => "Missing artist name."]; } $data = artist_info($URL, $API, $name); - return ["status" => "success", "data" => $data]; + return ["status" => "success", "data" => $data]; } else if ($request["type"] == "many_artists") { - $data = many_artists($URL, $API); - return ["status" => "success", "data" => $data]; + $data = many_artists($URL, $API); + return ["status" => "success", "data" => $data];} - } else { //error checking if the request is unknown - echo "Unknown type: " . $request['type'] . "\n"; - return ["status" => "error", "message" => "Unknown type: " . $request['type']]; - } + else { //error checking + echo "Unknown type: " . $request['type'] . "\n"; } } + $server = new rabbitMQServer(__DIR__ . '/../testRabbitMQ.ini', 'testServer3'); //connection to the broker -echo"DMZ START\n"; +echo "DMZ START\n"; $server->process_requests('requests'); + exit(); ?> From b6fa43b1c70fd14b0103571f9bbb55fab880fd48 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Thu, 12 Mar 2026 11:25:06 -0400 Subject: [PATCH 05/10] commented out not needed functions --- dmz-processor/processor.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/dmz-processor/processor.php b/dmz-processor/processor.php index 30cd82bb0..e615bfb28 100644 --- a/dmz-processor/processor.php +++ b/dmz-processor/processor.php @@ -42,6 +42,7 @@ function top_tracks($url, $api) { //get the top tracks "play_count" => (int)($track["playcount"] ), "listeners" => (int)($track["listeners"] ), "url" => $track["url"], +// "mbid" => $track["mbid"], ]; } @@ -67,9 +68,10 @@ function top_artists($url, $api) { //gets the top artists foreach ($data["artists"]["artist"] as $i => $artist) { //puts them into a list $artists[] = [ "rank" => $i + 1, - "name" => $artist["name"] ?? "", + "name" => $artist["name"], "listeners" => (int)($artist["listeners"] ?? 0), "play_count" => (int)($artist["playcount"] ?? 0), +// "mbid" => $artist["mbid"], ]; } @@ -81,7 +83,7 @@ function top_artists($url, $api) { //gets the top artists ]; } -function artist_info($url, $api, $name) { //gets the information on an artist +/*function artist_info($url, $api, $name) { //gets the information on an artist echo "Artist Info \n"; $data = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //artist.getInfo @@ -101,9 +103,11 @@ function artist_info($url, $api, $name) { //gets the information on an artist "play_count" => (int)($data["artist"]["stats"]["playcount"] ), "bio" => trim(strip_tags($data["artist"]["bio"]["summary"] )), "url" => $data["artist"]["url"], + "mbid" => $data["artist"]["mbid"], ] ]; } +*/ function many_artists($url, $api) { //gets info for 300 artists echo "300 Artists \n"; @@ -119,7 +123,7 @@ function many_artists($url, $api) { //gets info for 300 artists foreach ($data["artists"]["artist"] as $artist) { //loop through each artist $name = $artist["name"] ?? ""; - $info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //get info for each artist on the chart + $info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //gets info if (!$info || !isset($info["artist"])) { //skips if no data echo "No data for: $name \n"; @@ -127,11 +131,12 @@ function many_artists($url, $api) { //gets info for 300 artists } $results[] = [ - "name" => $info["artist"]["name"] ?? "", - "listeners" => (int)($info["artist"]["stats"]["listeners"] ?? 0), - "play_count" => (int)($info["artist"]["stats"]["playcount"] ?? 0), - "bio" => trim(strip_tags($info["artist"]["bio"]["summary"] ?? "")), - "url" => $info["artist"]["url"] ?? "", + "name" => $info["artist"]["name"], + "listeners" => (int)($info["artist"]["stats"]["listeners"]), + "play_count" => (int)($info["artist"]["stats"]["playcount"]), + "bio" => trim(strip_tags($info["artist"]["bio"]["summary"])), + "url" => $info["artist"]["url"], +// "mbid" => $info["artist"]["mbid"], ]; } echo "DONE \n"; @@ -157,14 +162,14 @@ function requests($request) { //handles the requests "tracks" => $tracks, "artists" => $artists]; - } else if ($request["type"] == "artist") { //calls function in charge of artists - $name = $request["name"] ?? ""; +// } else if ($request["type"] == "artist") { //calls function in charge of artists + // $name = $request["name"] ?? ""; - if ($name == "") { //error checking - return ["status" => "error", "message" => "Missing artist name."]; - } - $data = artist_info($URL, $API, $name); - return ["status" => "success", "data" => $data]; +// if ($name == "") { //error checking + // return ["status" => "error", "message" => "Missing artist name."]; } + +// $data = artist_info($URL, $API, $name); + // return ["status" => "success", "data" => $data]; } else if ($request["type"] == "many_artists") { $data = many_artists($URL, $API); From 4845687376215660587e4de1ab87d0e72eda8984 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Thu, 19 Mar 2026 14:04:52 -0400 Subject: [PATCH 06/10] remove cron.php. file not needed --- dmz-processor/cron.php | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 dmz-processor/cron.php diff --git a/dmz-processor/cron.php b/dmz-processor/cron.php deleted file mode 100644 index 5d8b87433..000000000 --- a/dmz-processor/cron.php +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/php -publish($request); From fce9ffaf0db7a194b003ec57aec89460651f0da3 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Thu, 19 Mar 2026 14:08:40 -0400 Subject: [PATCH 07/10] cleaned version of the processor --- dmz-processor/processor.php | 134 ++++-------------------------------- 1 file changed, 15 insertions(+), 119 deletions(-) diff --git a/dmz-processor/processor.php b/dmz-processor/processor.php index e615bfb28..ede975c66 100644 --- a/dmz-processor/processor.php +++ b/dmz-processor/processor.php @@ -22,120 +22,33 @@ function lastfm($url, $api_key, $method, $extras = []) { //call api return json_decode($data, true); //returns data } - -function top_tracks($url, $api) { //get the top tracks - echo "Top Tracks \n"; - - $data = lastfm($url, $api, "chart.getTopTracks") ; //chart.getTopTracks - - if (!$data || !isset($data["tracks"]["track"])) { //checks for error - echo "No Track Data"; - return null; - } - - $tracks = []; - foreach ($data["tracks"]["track"] as $i => $track) { //puts them into a list - $tracks[] = [ - "rank" => $i + 1, - "track_name" => $track["name"], - "artist" => $track["artist"]["name"], - "play_count" => (int)($track["playcount"] ), - "listeners" => (int)($track["listeners"] ), - "url" => $track["url"], -// "mbid" => $track["mbid"], - ]; - } - - echo "DONE \n"; - return [ //returns formatted list - "type" => "top_tracks", - "fetched_at" => date("Y-m-d"), - "payload" => $tracks - ]; -} - -function top_artists($url, $api) { //gets the top artists - echo "Top Artists \n"; - - $data = lastfm($url, $api, "chart.getTopArtists"); //chart.getTopArtists - - if (!$data || !isset($data["artists"]["artist"])) { //error checking - echo "No Artists Data \n"; - return null; - } - - $artists = []; - foreach ($data["artists"]["artist"] as $i => $artist) { //puts them into a list - $artists[] = [ - "rank" => $i + 1, - "name" => $artist["name"], - "listeners" => (int)($artist["listeners"] ?? 0), - "play_count" => (int)($artist["playcount"] ?? 0), -// "mbid" => $artist["mbid"], - ]; - } - - echo "DONE \n"; - return [ //returns formatted list - "type" => "top_artists", - "fetched_at" => date("Y-m-d"), - "payload" => $artists - ]; -} - -/*function artist_info($url, $api, $name) { //gets the information on an artist - echo "Artist Info \n"; - - $data = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //artist.getInfo - - if (!$data || !isset($data["artist"])) { //error checking - echo "No Data for Artist: $name\n"; - return null; - } - - echo "DONE \n"; - return [ //returns formatted info - "type" => "artist_info", - "fetched_at" => date("Y-m-d"), - "payload" => [ - "name" => $data["artist"]["name"] ?? "", - "listeners" => (int)($data["artist"]["stats"]["listeners"] ), - "play_count" => (int)($data["artist"]["stats"]["playcount"] ), - "bio" => trim(strip_tags($data["artist"]["bio"]["summary"] )), - "url" => $data["artist"]["url"], - "mbid" => $data["artist"]["mbid"], - ] - ]; -} -*/ - function many_artists($url, $api) { //gets info for 300 artists echo "300 Artists \n"; - $data = lastfm($url, $api, "chart.getTopArtists", ["limit" => 300]); + $top_artists = lastfm($url, $api, "chart.getTopArtists", ["limit" => 300]); - if (!$data || !isset($data["artists"]["artist"])) { //error checking + if (!$top_artists || !isset($top_artists["artists"]["artist"])) { //error checking echo "No Artists Data \n"; return null; } $results = []; - foreach ($data["artists"]["artist"] as $artist) { //loop through each artist + foreach ($top_artists["artists"]["artist"] as $artist) { //loop through each artist $name = $artist["name"] ?? ""; - $info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //gets info + $artist_info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //gets info - if (!$info || !isset($info["artist"])) { //skips if no data + if (!$artist_info || !isset($artist_info["artist"])) { //skips if no data echo "No data for: $name \n"; continue; } $results[] = [ - "name" => $info["artist"]["name"], - "listeners" => (int)($info["artist"]["stats"]["listeners"]), - "play_count" => (int)($info["artist"]["stats"]["playcount"]), - "bio" => trim(strip_tags($info["artist"]["bio"]["summary"])), - "url" => $info["artist"]["url"], + "name" => $artist_info["artist"]["name"], + "listeners" => (int)($artist_info["artist"]["stats"]["listeners"]), + "play_count" => (int)($artist_info["artist"]["stats"]["playcount"]), + "bio" => trim(strip_tags($artist_info["artist"]["bio"]["summary"])), + "url" => $artist_info["artist"]["url"], // "mbid" => $info["artist"]["mbid"], ]; } @@ -152,31 +65,14 @@ function requests($request) { //handles the requests if (!isset($request['type'])) { //error checking return ["status" => "error", "message" => "unsupported type"]; - } - if($request['type'] == "weekly_charts") { //calls functions for the weekly charts - $tracks = top_tracks($URL, $API); - $artists = top_artists($URL, $API); - return [ - "status" => "success", - "tracks" => $tracks, - "artists" => $artists]; - -// } else if ($request["type"] == "artist") { //calls function in charge of artists - // $name = $request["name"] ?? ""; - -// if ($name == "") { //error checking - // return ["status" => "error", "message" => "Missing artist name."]; } - -// $data = artist_info($URL, $API, $name); - // return ["status" => "success", "data" => $data]; - - } else if ($request["type"] == "many_artists") { +} elseif ($request["type"] == "many_artists") { $data = many_artists($URL, $API); - return ["status" => "success", "data" => $data];} + return ["status" => "success", "data" => $data]; - else { //error checking - echo "Unknown type: " . $request['type'] . "\n"; } +} else { //error checking + echo "Unknown type: " . $request['type'] . "\n"; + } } $server = new rabbitMQServer(__DIR__ . '/../testRabbitMQ.ini', 'testServer3'); //connection to the broker From cfb0760ab34ce902bd845933dfc5f310c4050476 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Tue, 28 Apr 2026 12:35:14 -0400 Subject: [PATCH 08/10] updated the API Processor --- dmz-processor/processor.php | 93 +++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 15 deletions(-) diff --git a/dmz-processor/processor.php b/dmz-processor/processor.php index ede975c66..2215c0477 100644 --- a/dmz-processor/processor.php +++ b/dmz-processor/processor.php @@ -8,12 +8,11 @@ $URL = "http://ws.audioscrobbler.com/2.0/"; -function lastfm($url, $api_key, $method, $extras = []) { //call api +function lastfm($url, $api_key, $method, $extras=[]) { //call api $query = array_merge([ - "method" => $method, + "method" => $method, "api_key" => $api_key, - "format" => "json", ], - $extras); + "format" => "json", ], $extras); $endpoint = $url . "?" . http_build_query($query); //creates url @@ -23,9 +22,9 @@ function lastfm($url, $api_key, $method, $extras = []) { //call api } function many_artists($url, $api) { //gets info for 300 artists - echo "300 Artists \n"; + echo "Artists \n"; - $top_artists = lastfm($url, $api, "chart.getTopArtists", ["limit" => 300]); + $top_artists = lastfm($url, $api, "chart.getTopArtists", ["limit" => 100000]); //limit # of artists if (!$top_artists || !isset($top_artists["artists"]["artist"])) { //error checking echo "No Artists Data \n"; @@ -34,7 +33,7 @@ function many_artists($url, $api) { //gets info for 300 artists $results = []; foreach ($top_artists["artists"]["artist"] as $artist) { //loop through each artist - $name = $artist["name"] ?? ""; + $name = $artist["name"]; $artist_info = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //gets info @@ -44,12 +43,12 @@ function many_artists($url, $api) { //gets info for 300 artists } $results[] = [ - "name" => $artist_info["artist"]["name"], - "listeners" => (int)($artist_info["artist"]["stats"]["listeners"]), + "name" => $artist_info["artist"]["name"], + "listeners" => (int)($artist_info["artist"]["stats"]["listeners"]), "play_count" => (int)($artist_info["artist"]["stats"]["playcount"]), - "bio" => trim(strip_tags($artist_info["artist"]["bio"]["summary"])), - "url" => $artist_info["artist"]["url"], -// "mbid" => $info["artist"]["mbid"], + "bio" => trim(strip_tags($artist_info["artist"]["bio"]["summary"])), + "url" => $artist_info["artist"]["url"], + "mbid" => $artist_info["artist"]["mbid"] ]; } echo "DONE \n"; @@ -60,6 +59,63 @@ function many_artists($url, $api) { //gets info for 300 artists ]; } + +function many_tracks($url, $api) { //many tracks + echo "Tracks \n"; + + $top_tracks = lastfm($url, $api, "chart.getTopTracks",["limit" => 100000]) ; //chart.getTopTracks + + if (!$top_tracks || !isset($top_tracks["tracks"]["track"])) { //checks for error + echo "No Track Data"; + return null; + } + + $tracks = []; + foreach ($top_tracks["tracks"]["track"] as $track) { //puts them into a list + $tracks[] = [ + "track_name" => $track["name"], + "artist" => $track["artist"]["name"], + "play_count" => (int)($track["playcount"] ), + "url" => $track["url"], + "mbid" => $track["mbid"] + ]; + } + + echo "DONE \n"; + return [ //returns formatted list + "type" => "many_tracks", + "fetched_at" => date("Y-m-d"), + "payload" => $tracks + ]; +} + +function single_artist($url, $api, $name) { //gets the information on a certain artist + echo "Artist Info \n"; + + $artist = lastfm($url, $api, "artist.getInfo", ["artist" => $name]); //artst.getInfo + + if (!$artist || !isset($artist["artist"])) { //error checking + echo "Artist not found: $name\n"; + return null; + } + + $artist[] = [ + "name" => $artist["artist"]["name"], + "listeners" => (int)($artist["artist"]["stats"]["listeners"]), + "play_count" => (int)($artist["artist"]["stats"]["playcount"]), + "bio" => trim(strip_tags($artist["artist"]["bio"]["summary"])), + "url" => $artist["artist"]["url"], + "mbid" => $artist["artist"]["mbid"] + ]; + + echo "DONE \n"; + return [ //returns formatted info + "type" => "single_artist", + "fetched_at" => date("Y-m-d"), + "payload" => $artist + ]; +} + function requests($request) { //handles the requests global $API, $URL; @@ -70,14 +126,21 @@ function requests($request) { //handles the requests $data = many_artists($URL, $API); return ["status" => "success", "data" => $data]; -} else { //error checking +} elseif ($request["type"] == "many_tracks") { + $data = many_tracks($URL,$API); + return ["status" => "success", "data" => $data]; + +} elseif ($request["type"] == "single_artist") { + $data = single_artist($URL,$API); + return ["status" => "success", "data" => $data]; + +} else { echo "Unknown type: " . $request['type'] . "\n"; } } $server = new rabbitMQServer(__DIR__ . '/../testRabbitMQ.ini', 'testServer3'); //connection to the broker -echo "DMZ START\n"; +echo "API ready \n"; $server->process_requests('requests'); - exit(); ?> From 4c667beb4d71999189bffba5144fc268b02d31ee Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Tue, 28 Apr 2026 12:36:48 -0400 Subject: [PATCH 09/10] update ini file --- testRabbitMQ.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testRabbitMQ.ini b/testRabbitMQ.ini index 30b4b0ea7..459368f8f 100644 --- a/testRabbitMQ.ini +++ b/testRabbitMQ.ini @@ -22,7 +22,7 @@ ROUTING_KEY = us.frontend AUTO_DELETE = true [testServer3] -BROKER_HOST = 100.88.147.61 +BROKER_HOST = 100.116.117.114 BROKER_PORT = 5672 USER = test PASSWORD = test From a6d62cb89e81cfc245474b7967af99cc47101102 Mon Sep 17 00:00:00 2001 From: mlm57-matt Date: Tue, 28 Apr 2026 12:37:15 -0400 Subject: [PATCH 10/10] updated file --- testRabbitMQClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testRabbitMQClient.php b/testRabbitMQClient.php index 2bbdc5224..241d999b5 100755 --- a/testRabbitMQClient.php +++ b/testRabbitMQClient.php @@ -4,7 +4,7 @@ require_once('get_host_info.inc'); require_once('rabbitMQLib.inc'); -$client = new rabbitMQClient("testRabbitMQ.ini","testServer"); +$client = new rabbitMQClient("testRabbitMQ.ini","testServer2"); if (isset($argv[1])) { $msg = $argv[1];