Generate a Daily Sitemap and Update using a URL String Input


Code Review

I wrote method generateSitemap, which is part of a large class, UpdateStocks. It generates a daily sitemap and can update it few times a day.

generateSitemap has an input string and called inside a for loop, similar to:

{pseudocode} for i=1 to 8000;     get input[i]; // for example: 'aapl-apple-technology-nasdaq-us-8f4c'     UpdateStocks::generateSitemap(input[i]); {/pseudocode} endfor; 

Would you be so kind and review it and help me to possibly make it faster, simpler or more efficient?

generateSitemap

  /**    *     * @return a large string in a txt file including all urls for a daily sitemap    */   public static function generateSitemap($  lurl){     $  dir=__DIR__ . self::DIR_FRONT_PUBLIC_HTML;      // url     $  sm=sprintf('%s%s%s',                 self::PROTOCOL.self::DOMAIN.self::SLASH.self::DIR_URL_KEYWORD_1.self::SLASH.self::DIR_URL_KEYWORD_2.self::SLASH,                 $  lurl,                 self::NEW_LINE         );     $  dt=new \DateTime('now');     $  dt=$  dt->format('Y-m-d'); // today     $  fn=$  dir . self::SITEMAP_PREFIX . $  dt . self::EXTENSION_TXT; // sitemap filename in public_html      // if daily sitemap already exits     if(file_exists($  fn)){       $  arr = preg_split('/\n/', trim(file_get_contents($  fn))); // array of links       $  i=0; // counter       foreach ($  arr as $  k=>$  lk){         if($  arr[$  k]==null){unset($  arr[$  k]);}         if(trim($  lk)===trim($  sm)){ // link already exist           $  i++;           if($  i>0){$  arr[$  k]=null;} // link already exist more than once         }else{           if($  k==sizeof($  arr)-1){             $  k++;             $  arr[$  k]=$  sm;             $  arr=implode(self::NEW_LINE, $  arr);             $  fh=fopen($  fn, 'wb');             fwrite($  fh, $  arr);             fclose($  fh);           }           continue;         }       }     }else{       $  fh=fopen($  fn, 'wb');       fwrite($  fh, $  sm);       fclose($  fh);     }       } 

Example of Inputs

a-agilent-technologies-healthcare-nyse-us-39d4 aa-alcoa-basic-materials-nyse-us-159a aaau-perth-mint-physical-gold-nyse-us-8ed9 aaba-altaba-financial-services-nasdaq-us-26f5 aac-healthcare-nyse-us-e92a aadr-advisorshares-dorsey-wright-adr-nyse-us-d842 aal-airlines-industrials-nasdaq-us-29eb aamc-altisource-asset-management-com-financial-services-nyse-us-b46a aan-aarons-industrials-nyse-us-d00e aaoi-applied-optoelectronics-technology-nasdaq-us-1dee aaon-basic-materials-nasdaq-us-238e aap-advance-auto-parts-wi-consumer-cyclical-nyse-us-1f60 aapl-apple-technology-nasdaq-us-8f4c aat-assets-real-estate-nyse-us-3598 aau-almaden-minerals-basic-materials-nyse-us-1c57 aaww-atlas-air-worldwide-industrials-nasdaq-us-69f3 aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4 aaxn-axon-enterprise-industrials-nasdaq-us-0eef ab-alliancebernstein-units-financial-services-nyse-us-deb1 abac-renmin-tianli-consumer-defensive-nasdaq-us-8701 abb-industrials-nyse-us-a407 abbv-abbvie-healthcare-nyse-us-9aea abc-amerisourcebergen-healthcare-nyse-us-bd9d abcb-ameris-bancorp-financial-services-nasdaq-us-df98 abdc-alcentra-capital-financial-services-nasdaq-us-96dd abeo-abeona-therapeutics-healthcare-nasdaq-us-aa0f abeow-market-us-d84d abev-ambev-1-consumer-defensive-nyse-us-a9b4 abg-asbury-automotive-consumer-cyclical-nyse-us-db5f abil-ability-technology-nasdaq-us-91a6 abio-arca-biopharma-healthcare-nasdaq-us-098e abm-abm-industries-industrials-nyse-us-bcbc abmd-abiomed-healthcare-nasdaq-us-2818 abr-arbor-realty-real-estate-nyse-us-68b1 abr-a-arbor-realty-real-estate-nyse-us-8c1d abr-b-arbor-realty-real-estate-nyse-us-97f2 abr-c-arbor-realty-real-estate-nyse-us-ee81 abt-abbott-laboratories-healthcare-nyse-us-c7fd abtx-allegiance-bancshares-financial-services-nasdaq-us-6913 abus-arbutus-biopharma-healthcare-nasdaq-us-c23f ac-associated-capital-financial-services-nyse-us-fca3 aca-arcosa-industrials-nyse-us-b429 

Part of sitemap-2019-03-15.txt:

domain.org/url[0]/url[1]/a-agilent-technologies-healthcare-nyse-us-39d4 domain.org/url[0]/url[1]/aa-alcoa-basic-materials-nyse-us-159a domain.org/url[0]/url[1]/aaau-perth-mint-physical-gold-nyse-us-8ed9 domain.org/url[0]/url[1]/aaba-altaba-financial-services-nasdaq-us-26f5 domain.org/url[0]/url[1]/aac-healthcare-nyse-us-e92a domain.org/url[0]/url[1]/aadr-advisorshares-dorsey-wright-adr-nyse-us-d842 domain.org/url[0]/url[1]/aal-airlines-industrials-nasdaq-us-29eb domain.org/url[0]/url[1]/aamc-altisource-asset-management-com-financial-services-nyse-us-b46a domain.org/url[0]/url[1]/aan-aarons-industrials-nyse-us-d00e domain.org/url[0]/url[1]/aaoi-applied-optoelectronics-technology-nasdaq-us-1dee domain.org/url[0]/url[1]/aaon-basic-materials-nasdaq-us-238e domain.org/url[0]/url[1]/aap-advance-auto-parts-wi-consumer-cyclical-nyse-us-1f60 domain.org/url[0]/url[1]/aapl-apple-technology-nasdaq-us-8f4c domain.org/url[0]/url[1]/aat-assets-real-estate-nyse-us-3598 domain.org/url[0]/url[1]/aau-almaden-minerals-basic-materials-nyse-us-1c57 domain.org/url[0]/url[1]/aaww-atlas-air-worldwide-industrials-nasdaq-us-69f3 domain.org/url[0]/url[1]/aaxj-ishares-msci-all-country-asia-ex-japan-nasdaq-us-c6c4 domain.org/url[0]/url[1]/aaxn-axon-enterprise-industrials-nasdaq-us-0eef domain.org/url[0]/url[1]/ab-alliancebernstein-units-financial-services-nyse-us-deb1 domain.org/url[0]/url[1]/abac-renmin-tianli-consumer-defensive-nasdaq-us-8701 domain.org/url[0]/url[1]/abb-industrials-nyse-us-a407 domain.org/url[0]/url[1]/abbv-abbvie-healthcare-nyse-us-9aea domain.org/url[0]/url[1]/abc-amerisourcebergen-healthcare-nyse-us-bd9d domain.org/url[0]/url[1]/abcb-ameris-bancorp-financial-services-nasdaq-us-df98 domain.org/url[0]/url[1]/abdc-alcentra-capital-financial-services-nasdaq-us-96dd domain.org/url[0]/url[1]/abeo-abeona-therapeutics-healthcare-nasdaq-us-aa0f domain.org/url[0]/url[1]/abeow-market-us-d84d domain.org/url[0]/url[1]/abev-ambev-1-consumer-defensive-nyse-us-a9b4 domain.org/url[0]/url[1]/abg-asbury-automotive-consumer-cyclical-nyse-us-db5f domain.org/url[0]/url[1]/abil-ability-technology-nasdaq-us-91a6 domain.org/url[0]/url[1]/abio-arca-biopharma-healthcare-nasdaq-us-098e domain.org/url[0]/url[1]/abm-abm-industries-industrials-nyse-us-bcbc domain.org/url[0]/url[1]/abmd-abiomed-healthcare-nasdaq-us-2818 domain.org/url[0]/url[1]/abr-arbor-realty-real-estate-nyse-us-68b1 domain.org/url[0]/url[1]/abr-a-arbor-realty-real-estate-nyse-us-8c1d domain.org/url[0]/url[1]/abr-b-arbor-realty-real-estate-nyse-us-97f2 domain.org/url[0]/url[1]/abr-c-arbor-realty-real-estate-nyse-us-ee81 domain.org/url[0]/url[1]/abt-abbott-laboratories-healthcare-nyse-us-c7fd domain.org/url[0]/url[1]/abtx-allegiance-bancshares-financial-services-nasdaq-us-6913 domain.org/url[0]/url[1]/abus-arbutus-biopharma-healthcare-nasdaq-us-c23f domain.org/url[0]/url[1]/ac-associated-capital-financial-services-nyse-us-fca3 domain.org/url[0]/url[1]/aca-arcosa-industrials-nyse-us-b429 

Issue with sitemap

Hey guys

My sitemap hasn’t lately been indexed by Google. When i try to fetch my sitemap, i get following error:

"’noindex’ detected i… | Read the rest of http://www.webhostingtalk.com/showthread.php?t=1756407&goto=newpost

Does linking to your sitemap help SEO?

Ok, so obviously I know the importance of having a sitemap and linking to it from your own website. That is not my question at all. No my question is much more complex and intriguing.

But first…

A little back story to my question

I was doing some competitive link analysis for a client and found that one of their competitors was building links to their sitemap.xml file. This lead me to start to ask a few questions…

Having a link to your sitemap would ensure Google crawls your…

Does linking to your sitemap help SEO?

Export JSON sitemap of views

I have a Drupal 8 site that is using a bunch of custom views with REST endpoints. These views contain a bunch of content nodes on them which make up a single page.

I have been able to generate an XML sitemap of the views by using Simple XML Sitemap module but I am wanting to know if (and how) it’s possible to generate a JSON sitemap of all the views and the paths that are associated with REST but dynamically?

Thanks

Magento 2.2.5 can’t find sitemap while it is generated

I’m struggling with an weird issue. I can’t make any custom files / folders in my root of magento. I want to make a custom folder with some images, resulating in 404 errors when trying to reach the path of this images.

Also, the generated XML Sitemap throws an 404 error. The path for the sitemap is /sitemaps/sitemap.xml. Magento can’t find this path. Is there a seting i’m overlooking? Because first it worked well.

Hope someone can help me with this!

Generate SITEMAP with Angular App in S3 routing provider Amazon (SEO)

Eu tenho uma aplicação em Angular 5 desenvolvida e preciso implementar o SEO nela. Utilizei esse tutorial com Puppeter para fazer o prerender das páginas e foi gerado o html de acordo com as rotas. E após isso, fiz o upload da pasta dist no S3. Com isso, ao testar pelo site https://www.xml-sitemaps.com/ ele reconhece as páginas no item “Scanned”, porém ao término ele só encontra a pasta raiz e diz que as restantes foram como links quebrados. Alguma ideia para me ajudar? Utilizei esse tutorial para fazer o build da aplicação e gerar o dist https://blog.cloudboost.io/prerender-an-angular-application-with-angular-cli-and-puppeteer-25dede2f0252

Análise do sitemap

Links quebrados após o sitemap generator