Jump to content

PW-Install-Routine, HTTP-Requests


horst
 Share

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
Link to comment
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. 

Link to comment
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
Link to comment
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. 

Link to comment
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);
}

Link to comment
Share on other sites

 Share

×
×
  • Create New...