Generate a Daily Sitemap and Update using a URL String InputRemove parameters from string containing URLUpdate URL with new parameter valueJava class that generates a short URL string for an input stringURL link SEO and security using LaravelRead and replace URL from PDF fileParsing URL query and appending it at end of the other URLRecreating a URL stringRemove a query string parameter from a URLError handling with C-string input using get() and getline()Splitting URL query string to key-value pairs

What are substitutions for coconut in curry?

Why Choose Less Effective Armour Types?

Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is

Credit cards used everywhere in Singapore or Malaysia?

Gravity magic - How does it work?

How can I track script which gives me "command not found" right after the login?

What approach do we need to follow for projects without a test environment?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

SOQL: Populate a Literal List in WHERE IN Clause

Knife as defense against stray dogs

Why would a flight no longer considered airworthy be redirected like this?

Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?

Are all passive ability checks floors for active ability checks?

Does Mathematica reuse previous computations?

How to write cleanly even if my character uses expletive language?

How to change two letters closest to a string and one letter immediately after a string using notepad++

In a future war, an old lady is trying to raise a boy but one of the weapons has made everyone deaf

Identifying the interval from A♭ to D♯

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

Instead of Universal Basic Income, why not Universal Basic NEEDS?

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Welcoming 2019 Pi day: How to draw the letter π?

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

Do I need to be arrogant to get ahead?



Generate a Daily Sitemap and Update using a URL String Input


Remove parameters from string containing URLUpdate URL with new parameter valueJava class that generates a short URL string for an input stringURL link SEO and security using LaravelRead and replace URL from PDF fileParsing URL query and appending it at end of the other URLRecreating a URL stringRemove a query string parameter from a URLError handling with C-string input using get() and getline()Splitting URL query string to key-value pairs













0












$begingroup$


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









share|improve this question









$endgroup$
















    0












    $begingroup$


    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









    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      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









      share|improve this question









      $endgroup$




      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






      beginner php algorithm strings url






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 51 mins ago









      EmmaEmma

      164112




      164112




















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215553%2fgenerate-a-daily-sitemap-and-update-using-a-url-string-input%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215553%2fgenerate-a-daily-sitemap-and-update-using-a-url-string-input%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

          Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar