Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:34:06+00:00 2026-05-24T22:34:06+00:00

I am running a PHP script which calls out to world weather online to

  • 0

I am running a PHP script which calls out to world weather online to retrieve wave height, wave duration and water temperature by latitude longitude. However my host only allows 10 second script execution. I was wondering if I could trouble the community to give me some ideas / pointers on optimizing my script, as I do not have access to the php_ini on my host. The script works, only updates around 35 records. There are 100 records total. Me thinks I am throwing to much data at the world weather API.

Here is my script:

$connection=mysql_connect('myhost', 'user', 'post');
if (!$connection) {  die('Not connected : ' . mysql_error());}


$db_selected = mysql_select_db('ilovebigbutts', $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}

// Here I am selecting the lat long and pri_id from table
$query = "SELECT * FROM beaches";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}

while ($row = @mysql_fetch_assoc($result)) {
$id = $row["pri_id"];
$lat = $row["lat"];
$lng = $row["lng"];

$feed_url = "http://free.worldweatheronline.com/feed/marine.ashx?  key=xxxxxxxxxxxx&q=".$lat.",".$lng."&format=xml";
$xmlString = file_get_contents($feed_url);  
$xml = new SimpleXMLElement($xmlString); 
$items = $xml->xpath('weather/hourly');
$closeItems = array(); 
$new_array = array(); 
foreach($items as &$item)  
{ 
$waves = $item->swellHeight_m;
$wave_secs = $item->swellPeriod_secs;
$water_temp = $item->waterTemp_F;
$query1 = "UPDATE beaches SET waves = '$waves', wave_secs = '$wave_secs', water_temp = '$water_temp' WHERE pri_id = '$id' LIMIT 1";
  $update_result = mysql_query($query1);
  if (!$update_result) {
    die("Invalid query: " . mysql_error());
  }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:34:07+00:00Added an answer on May 24, 2026 at 10:34 pm

    I’m surprised this is taking > 10 seconds. Do you have an index on pri_id ? If you do, you could always put a limit on your original select query and do it in chunks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running a cron job every five minutes which calls a php script
I've got a PHP script which I'm running from a command line (windows) that
I have a long running PHP script that has a memory leak which causes
I have a PHP script (running on a Linux server) that ouputs the names
What is the best way to keep a PHP script running as a daemon,
When running PHP in CLI mode, most of the time (not always), the script
I'm trying to run a PHP script which has pg_connect($connection_string) and it just crashes
I'm running a third party script by using a wrapper class I've written which
I have ajax call which pulls from the processing script 'getajax.php'. Call is made
I am trying to trigger the running of a shell script using PHP. Essentially,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.