Jump to content
horst

PW-Install-Routine, HTTP-Requests

Recommended Posts

Hi,
 
while exploring PW from the filesystem I've found 'Http.php' and as of my difficultys when starting with PW, I was wondering why not sending a HTTP-HEAD-Request to the admin-page-url at the end of the install process and inform the user if .htaccess isn't configured the right way.

So, I was a bit wiser after opening the class-file: there was no support in it for HEAD, only GET and POST. As I've build a own http-client-class a hundred years ago, it was not much work to implement the HEAD-method as well.

  (added 1 Line)

Maybe it should be added a http->status(url-to-adminpage)-check at end of install-routine to inform the user if it responses other than 200. (at least a link to apropriate forum-topic or provide direct information how to solve that)
 
----
Edit/Added: Every few days a new user run into same problem look at this post and the following two.

(I really can feal the pain he has). And all the helpful people here try to explain how to solve it everytime and again and again.

So, if it is not a kind of test to new users, the install-routine should solve that for them, and other as I've mentioned above, it should/could be done in the background, because everything needed is the .htaccess-file which is created by PW itself and some HTTP-Requests.

If default install is 404 for admin page: compare $_SERVER['DOCUMENT_ROOT'] with install folder of PW and write appropriate Path as RewriteBase into .htaccess-file and check again. If it responses '200 OK' now, - fine. If not, - tell user that there are Problems with this and point him to Forum-FAQ.


So, if it is actually a test to the new users weakness or strength with stressy situations, ok - any admin/moderator should silently delete this post and I never will ask again.  :-)
----
 

---

In API I have not found how we can use the WireHttp-class, (Searchphrases like HTTP and Request etc are not very useful)


Can someone point me to it please? :rolleyes:

  • Like 2

Share this post


Link to post
Share on other sites
So, I was a bit wiser after opening the class-file: there was no support in it for HEAD, only GET and POST. As I've build a own http-client-class a hundred years ago, it was not much work to implement the HEAD-method as well.

The WireHttp class is a fairly recent addition to the ProcessWire core, and as you saw it's very minimal at present. I had thought we'd keep adding to it. I like what you've added, and would definitely like to include your additions if that's alright with you?

If default install is 404 for admin page: compare $_SERVER['DOCUMENT_ROOT'] with install folder of PW and write appropriate Path as RewriteBase into .htaccess-file and check again

I think the problem here is that very often the .htaccess is not writable, so I don't really like building around something that we may or may not be able to do. I have never personally come across a situation that could be fixed by setting the RewriteBase, though I know others have. What may be a good approach for us is to just have a Troubleshooting section in the readme file, pointing people where to look in the .htaccess file if things aren't working. It does seem like more often than not, the problem isn't the .htaccess file but rather than server not reading it… something that beyond our ability to affect. Still, I like anything that makes it easier for users to install or troubleshoot, but I think this also represents a very small portion of installations. We'll have to keep looking at this though. 

Share this post


Link to post
Share on other sites

Oh, I see - you're right. The .htacces-file mostly would be not writable and also more often isn't the problem.

Maybe only test with HTTP-HEAD for the admin-page and inform the user if it is not reachable.

So he get warned and frustration isn't that big as it could be now <_<

And yes, I would like if you add the additions to the class.

( afterwards I can tell everyone who wants to hear about or not, that I've provided code to the core of one of the best CMS out there!  :biggrin: )

( but I wouldn't tell that it actually was a total of 6 or 7 lines :-X )

  • Like 3

Share this post


Link to post
Share on other sites

Sounds good, I think this makes sense for the installer. Thanks also for your additions to this class, I am putting them in today and should have them committed to the 2.3 source before release. 

One thing I would be worried about is just those cases where there is some firewall that blocks the server from accessing itself. I've run into this issue with a couple of people that were trying to verify their FormBuilder or ProCache license keys, and none of the WireHttp methods worked, despite falling back to sockets. So it seems like for one reason or another, there are servers out there that just don't accept outbound http requests (or have some firewall for local requests). I can't say for certain how common or rare this is, but am hoping it's rare. Can you think of any other fallbacks we should add to WireHttp, or do you think we've already got everything we need? I was toying with the idea of adding a CURL fallback option. 

Share this post


Link to post
Share on other sites

Horst, your file had comments speculating about what to do with the reasontext. Here's how I added it. Let me know if this makes sense:

/**
 * Send to a URL using HEAD and return the status code (@horst)
 *
 * @param string $url URL to request (including http:// or https://)
 * @param array $data Array of data to send (if not already set before)
 * @param bool $textMode When true function will return a string rather than integer, see the statusText() method.
 * @return bool|integer|string False on failure or integer of status code (200|404|etc) on success.
 *
 */
 public function status($url, array $data = array(), $textMode = false) {
  $responseHeader = $this->send($url, $data, 'HEAD');
  if(!is_array($responseHeader)) return false;
  $statusCode = (preg_match("=^(HTTP/\d+\.\d+) (\d{3}) (.*)=", $responseHeader[0], $matches) === 1) ? intval($matches[2]) : false;
  if($textMode) $statusCode = isset($matches[3]) ? "$statusCode $matches[3]" : "$statusCode";
  return $statusCode;
}

/**
 * Send to a URL using HEAD and return the status code and text like "200 OK"
 *
 * @param string $url URL to request (including http:// or https://)
 * @param array $data Array of data to send (if not already set before)
 * @return bool|string False on failure or string of status code + text on success.
 *   Example: "200 OK', "302 Found", "404 Not Found"
 *
 */
public function statusText($url, array $data = array()) {
  return $this->status($url, $data, true);
}

Share this post


Link to post
Share on other sites

Horst, your file had comments speculating about what to do with the reasontext. Here's how I added it. Let me know if this makes sense:

It not only makes sense, it is also elegant.

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By cmg
      I have just installed PW, with apparent success - but at the very end I got a series of error messages relating to the file Session.php:
      Warning: session_name(): Cannot change session name when headers already sent in /homepages/15/d465648144/htdocs/4x3/wire/core/Session.php on line 246
      Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /homepages/15/d465648144/htdocs/4x3/wire/core/Session.php on line 249
      Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /homepages/15/d465648144/htdocs/4x3/wire/core/Session.php on line 250
      Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /homepages/15/d465648144/htdocs/4x3/wire/core/Session.php on line 251
      Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /homepages/15/d465648144/htdocs/4x3/wire/core/Session.php on line 252
      The home page of my site displays OK, but when I click on the nav buttons I get errors. Same when I use the admin URL.
      Help!
      Chris
       
       
       
       
       
    • By Peter Knight
      Hi guys
      is there a checklist of items I should consider for diagnosing a series of pages which display a 404 error?
      Basically I have built a Blog and all my posts are under a folder called 'Posts'. Some of these pages successfully display while others display a 404 page. 
      This is what I have confirmed so far...
      1. All pages are within the same root folder 'Posts'
      2. All pages have the same template and fields completed
      3. All pages have the same properties under Settings > Who can access this page
      4. Pages have no redirects in place
      5. Pages have no special characters or anything funky in the URL slug
      There are no errors showing in the log either so I am stuck 😕
      Thanks
    • By alanxptm
      Hi, I have already tried in different ways and many times to migrate but I always have issues at the end.
      Here's what I have done so far:
       
      case 1:
      1. Install PW on live server (all normal)
      2. Import local DB into live DB
      3. Front page site seems to work but I cannot login into admin page
      case 2 (I'm currently on this stage):
      1. Copied all files from local to live server
      2. Import local DB into live empty DB
      3. Front page works, but any other page and admin page are 404
       
      In both cases:
      - I have changed config.php info accordingly to live server (DB name, DB user and pwd, userauthsalt code)
      - Uncommented RewriteBase / and RewriteBase /pw/ lines on .htaccess
      - applied owner and group permissions to www-data for PW location
      - applied permissions to folders and files accordingly
      - applied a2enmod rewrite to apache2 on live server and restarted service
       
      I have read some posts (Ryan's too) about migration and it seems to me that I'm doing it fine, don't know what it fails-
      I'm on VMWare machine, Ubuntu Server 18.04, php 7.2, phpMyAdmin 5.0.1
      Hope you can help me, thanks in advance
    • By rushy
      Hi. I've been using Processwire for a few years now and installed it on a few different shared hosting servers without issues, but I'm now running into an issue on a Fasthosts shared server that I've not seen before. The installation goes ok and I have a working default site profile but I am unable to complete any uploads of images. It just hangs at the progress spinner during the upload. I thought it might be a priviledge issue so have temporarily set the dir / file privs. as 777 / 666 just to test that but it made no difference. I have no errors in the wire log. In server error log I have:
      set_time_limit() has been disabled for security reasons in ....htdocs/wire/core/ImageSizerEngine.php on line 1035 and i note in the assets/file dir. where the image is being stored the date on the file being created has a year of 1970 and 0 length. If I leave the page this file disappears and nothing has been stored. 
      Does anyone know how I can enable set_time_limit if this is likely to be the problem? 
      Many thanks! Paul
    • By Robin S
      After forgetting the class name of the wonderful AdminPageFieldEditLinks module for what feels like the 100th time I decided I needed to give my failing memory a helping hand...
      Autocomplete Module Class Name
      Provides class name autocomplete suggestions for the "Add Module From Directory" and "Add Module From URL" fields at Modules > New.
      Requires ProcessWire >= v3.0.16.
      Screencast

      Installation
      Install the Autocomplete Module Class Name module.
      Configuration
      Add Module From Directory
      Choose the type of autocomplete suggestions list: "Module class names from directory" or "Custom list of module class names". The latter could be useful if you regularly install some modules and would prefer a shorter list of autocomplete suggestions. The list of class names in the modules directory is generated when the Autocomplete Module Class Name module is installed. It doesn't update automatically (because the retrieval of the class names is quite slow), but you can use the button underneath when you want to retrieve an updated list of class names from the directory. Add Module From URL
      If you want to see autocomplete suggestions for the "Add Module From URL" field then enter them in the following format:
      [autocomplete suggestion] > [module ZIP url]
      Example: RepeaterImages > https://github.com/Toutouwai/RepeaterImages/archive/master.zip Awesomplete options
      The "fuzzy search" option uses custom filter and item functions for Awesomplete so that the characters you type just have to exist in the autocomplete suggestion item and occur after preceding matches but do not need to be contiguous. Uncheck this option if you prefer the standard Awesomplete matching. Custom settings for Awesomplete can be entered in the "Awesomplete options" field if needed. See the Awesomplete documentation for more information.  
      https://github.com/Toutouwai/AutocompleteModuleClassName
      https://modules.processwire.com/modules/autocomplete-module-class-name/
×
×
  • Create New...