In regards to Can a PHP Proxy call Javascript functions like a click I'm investigating a solution that involves using PHP's HTTP class to simulate a client's browser.
Does anyone know if the PHP HTTP class supports javascript functions? Can you recommend any others that do?
Thanks!
No, it does not. You have to implement this yourself. If you want to have it all-serverside, look into phpjs, j4p5 or better yet the spidermonkey pecl extension. http://pecl.php.net/package/spidermonkey
A better alternative might be to script a real browser yourself via an XPI plugin / XPCOM bridge. There once was an extension called "JSSh", and another "SD connector", http://www.activestate.com/blog/2008/05/jssh-replacement-sd-connector
Neither of these options is simple. That's why nobody has done it, and why such extravagant features are specifically not in the HTTP class.
An Http stream handler is not in any way related to a browser. It will not generate a DOM tree, block ads or execute javascript - it is just a library handling the http protocol.
Related
I'm trying to make a JSON call library. It has the following features.
be able to customize the header
be able to POST any data to server(including form-encoding (a=1&b=2&c=3) and JSON data chunk)
parse the response and return as a JSON object
I searched in other questions and found that there are only two answers.
use file_get_contents(). This way is pretty simple and easy to use; however, you cannot do anything more than get the content -- you cannot add headers, cannot use POST. But it is usually supported by all servers.
use curl. This way seems powerful and you can do nearly everything with it. The disadvantage is that you have to install libcurl and php-curl support on your server, which means you may not use it on servers that have no curl installed.
So, if I want to develop a common library that can be used on most server, is curl a good choice?
Is there any other ways to do this?
In a short word, I'm looking for a PHP version of urllib2 in python - easy to use, powerful, and reliable.
You have two options: curl and HTTP stream context options. Both can accomplish what you have described; curl might not be installed everywhere, while stream contexts are a core feature and are always available.
Actually, you can also implement your library using sockets, which would be more work but will probably allow you greater control if you need to do weirder things with your requests.
As i know, curl is included in mostly on many server, since it supported from 4.0.2 PHP version natively.
Also there is a native php function header, which customizes your response's headers by simply using like this -> header('location: index.php'), header('cache-control: ok') and so on. You can view Network Functions section on php.net
Googling I've found this article:
http://java.dzone.com/tips/generating-client-java-code
It talk about how to generate a "JAVA" code with SOAP UI client, but what I need is to generate code php with soap UI or other resource.
Is this possible? exist any other resource to make it work that?
thank you for your answers..
Regards.
soapUI will not generate PHP code.
Fortunately, in PHP there often isn't a need to generate proxy classes. Instead, use SoapClient and simply call the SOAP methods you need outright. You can find simple examples at various blogs.
If the service with which you're interacting uses lots of complex types, then you may indeed want to auto-generate some PHP code and make use of SoapClient's classmap option.
Is there a way to simply send a erb file to a ruby parser get the answer back and send it to client with NGINX? Without all the passenger stuff? It should be easy i guess. I DON'T want to use any rails stuff, don't tell me i should use rails etc.
I created a script to do this two years ago, called ruby-cgi, in response to a similar question. I believe it does exacty what you want. Just set it up the same way you would set up other CGI/FastCGI handlers.
The following gems are available (sorted by feature completeness desc):
rack-server-pages
rhr
Of course you can, try this. But I would highly recommend using Sinatra as it's more like a ruby way of serving web pages like in php
I am trying to proxy through php for a JS RSS feed. The company I am doing this for may or may not want cURL installed. If that is the case I may need some sort of library that can simply be included in php rather than go through apache and all of that. Is there a library that can handle something like that? What other options do I have in this case?
Thanks!
Zend_HTTP provides a wrapper for fopen, file_get_contents and CURL out of the box, it makes it much more simpler to store / read cookies, make POST requests and so on.
wget, fopen, and file_get_contents are other options you can use to use for a proxy.
I want to use CURL library but I don't want to install it in a hard way
I just want to do something like this
require_once('curl.php');
I am not sure if this possible or not? and where can I found this CURL class?
thanks
PHP requires that its built with the cURL library, see:
http://www.php.net/manual/en/curl.installation.php
So you would install libcurl-devel for your system and then compile PHP with
--with-curl
And maybe
--with-curl=/path/to
If you installed it in a non-standard location.
You're copy of PHP is either going to have to have been built with Curl, or dynamically load it in (because Curl is not originally written in PHP, it's a C library).
Create a simple script that calls phpinfo(). If curl was built in, it should show up on this page.
phpinfo();
There is a Pure PHP Curl implementation called libCurlEmu
Just bear in mind: you should only use this kind of stuff as a last resort if you can't get the extensions to work.
There is also a standalone version called "MyCurl", that you can include without installation:
http://www.phpclasses.org/package/3588-PHP-Pure-PHP-implementation-of-the-cURL-library.html
i used it in my project and it worked fine with http-requests.
This class provides an alternative implementation of the cURL extension functions in pure PHP.
It automatically detects whether the cURL library is available. If it is not available, it defines several functions with the same names of the cURL extension that use the class to emulate part the original functionality.
Currently it implements the functions: curl_init, curl_exec, curl_setopt and curl_close. Several of the most important options can be set with the curl_setopt function.
although it has some small bugs, it works aftre fixing this:
the example doesent work out of the box, cause the domain lazywebmastertools.com is not reacheable
there is an # needed if the requested domain doesent end with "/":
return "/".#$tmp[1];
if you dont use a proxy, you have to set
if (isset($this->proxy) and $this->proxy["host"])...
if (isset( $this->headers["location"]) and $this->headers["location"] > "") {...
the drawback is, that this class doesent support https. there you would need the Snoopy Class:
https://stackoverflow.com/a/1154247/1069083