Yii Best way to serve dummy RSS in Test - php

I have a PHP Yii application that uses an RSS feed reader. I wanted to develop some good tests, and I wanted to attempt to read an RSS feed under my own control as part of my test suite. The idea is I request this feed from "my.localhost/testfeed/{name}" and my application is served locally at "my.localhost"
I made a controller (TestFeedController) which uses the CViewAction to serve static rss files (stored in .php files). I had to put these in "protected/views/testFeed/pages/" to make it work.
I wanted to store the files in "protected/tests/views/testFeed/pages/" to separate them better from actual application code, but was unable to get this to work (I tried to overload getViewPath()). Is there a way to get a view file in CViewAction that is NOT in "protected/views/*"?
Is there a better way to test reading a "remote" RSS file which is under my local control? I considered serving it on another virtual host, but I wanted to keep the project tests with the project.

You could use RenderInternal for your test files and pass it an absolute filepath (e.g., dirname(FILE).'/../tests/views/..etc..'

Related

Using XML files for PHP web app

I'm thinking of using XML for storing users content on my web app. I am a php newbie and don't know much about how I would do this.
The content is private to the user, not shared public or for passwords or anything. So I was wondering how I can create and edit xml files on the backend part of the server, privately accessed by PHP like what it does with mySQL.
My questions are: 1) Is it possible 2) If so, how would I do it using php etc.
Put all xml files in a folder that is not accessible via the web, so outside of your document root. Alternatively, you can use .htaccess to restrict access to that folder.
For reading and writing those xml files from your directory, you can use simplexml. You don't need anything else despite pure php and some xml processing.
This should get you started ;).
Theoretically it is possible. by making your xml in php files format which output xml formatted tags after PHP authentication. The PHP files will be created dynamically using PHP filesystem functions and will be modified also, for each users in a specified folder(s) for your users.

Serve a PHP website with PHP files being remote

This is the situation:
I have a LAMP server, which serves HTML, PHP, etc... Now I have remote folder, somewhere in the web, which has a directory full of PHP files, images, an MVC folder structure (CodeIgniter), etc...
Now, What I want to do is that instead of every time I want to serve those PHP files, instead of downloading them and uploaded them into my LAMP server, I want to use those PHP files directly and serve them in my LAMP server.
Again, I want the PHP files from a folder in another server, which I only have access to the direct link to each individual file, being serve in my LAMP server, so if I access my website, for instance: www.website.com/page1, gets the folder structure from the remote web server or all PHP files, and get serve within my server.
I know this sounds a little bit complicated but I'm not sure what to use... Maybe reverse proxy? Do you think I may download the files directly and constantly syncing the files? If anyone gets with a good solution I may even pay that person...
EDIT(1)
Good answers so far... but I think I did not make a good question so here it goes again:
I have access to a "list" of PHP files, and in order to get them I need to authenticate myself using oath via PHP. Once I get authenticated, I can retrieve a list of PHP, html, etc.. files, each one of them having a public URL that anyone can access. So the think is that instead of downloading all files in that repository, and serve those files, I want to be able to reuse that repository's web space and I just serve these files myself. So basically I want to be able to have symbolic links to urls, which I think is not possible, but being able to just read the files and serve the PHP logic, even though the files are elsewhere.
I'm concern about the security issues involved, but if someone could help me I will be thankful... Also if you are interested in what I'm doing I always can use a partner for this project which I intent to use it in charity, but still can pay that person.
This is not a smart thing to do. You open yourself up to potential security issues, but at a minimum, you will significantly slow your site down.
I would recommend that you simply script synchronizing the files on both servers over SSH by a script.
Edit: ManseUK's suggestion if rsync is also a good one.
If you have ftp access to the remote server, you could mount the folder using fuse, and serve as usual for apache.
Do you have the ability to mount the remote folder as an NFS volume, or perhaps with SSHFS? If those options are available, either could work for you. You'd mount the remote folder locally and tell your local web server to serve files from that path.
Not that it would be the most efficient setup in the world, but I don't know why you have all this split apart in the first place. ;)
You could write a cronjob to grab the remote file list every X minutes/hours/days then store the results locally, then write a simple script to parse those results upon request. Alternatively, you could still use an NFS or SSHFS mount to read the remote paths in real time and build whatever URL's you need.

How to copy an external image to local?

I want to retrive an http external image an copy it to a folder on my server (eg. /images/example.jpg)
Is there a way to do this with symfony 2.0 or with basic PHP 5 functions?
you can do it like this:
file_put_contents('tmp.jpg', file_get_contents('http://static.adzerk.net/Advertisers/3603.jpg'));
But, be careful, if it's a web page, it maybe very slow, depending on the speed of image page.

How to create a web page which seamlessly hosts a script on another webserver?

I have written a DNS security testing tool in PHP which relies on the webserver having BIND installed locally. I need to add this tool to our existing website however it's against policy to have BIND on the main web server. I have been allocated a new server if I need it and I'm trying to find the best solution to make this tool appear to be part of the main website (i.e. under the same domain e.g. domain.com/tool)
My first thought was to make a page on the main web server and host the tool within an iframe. This way, the tool can fit seamlessly into the existing site without having to recreate and maintain the sites themes and templates on the second server (header, footer etc). However, the script relies on being able to do a meta refresh redirect to a 2nd script which displays the results (the redirect is required to give time for the security tool to run). Im not sure if this can be done all within an iFrame. Any suggestions or methods that might be better than using an iframe?
Just as an idea: Your tool could generate a JSON response, and then you could use padded JSON to get it. With a little bit of work, you could do all the things you want using XMLHTTPRequests.

Online Image Slideshow Question. File Access Problems

I have a flash .swf file that I embed on my webpage. On my server I have the .swf file and multiple image folders. I would like to load every file in one of those folders into the flash slideshow. How should I go about doing this? I tried used Air but it doesn't work on my system as an application so I doubt it will work online. Eventually I plan on making a menu where you can select different folders to display and since they are of different sizes, a foreach loop would be optimal. Keeping a txt file with the number of images is also possible if theres a way to read that in, but I would prefer the more dynamic approach. I am working towards using php for the website if that helps find a solution.
Thanks,
-Mike
Also my slideshow works great online currently but i have to hardcode in the number of files.
I would suggest to have a PHP script on your server that takes care of parsing those folders, and return the list of files to Flash (with a valid public URL).
Basically at your application startup, you would call the PHP script to retrieve the full list of file (XML is a good format to be returned, or AMF if you have a lot of folders/files).
After all you have to do is manipulate that data to load whatever folder/files the user is willing to see.
Just for your information, Flash doesn't have access to the Filesystem, so it's impossible to parse folders directly from Flash. (However It is possible with an Air Application)

Categories