11 Replies - 106198 Views - Last Post: 19 June 2012 - 04:25 AM Rate Topic: -----

#1 chalfontonline   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-August 08

Run a php file from another php file

Posted 15 August 2008 - 02:06 AM

Hi

I have a file with parameters that I run from a browser normally.

This is the url I run. http://www .mysite.co.uk/shop/googlefroogle.php?feed=yes&upload=yes&type=products

I tried setting this up on a cron job, but my web server provider tell me I can not do this as it will not work with parameters.

I have a cron job running for an import routine.

Can someone assist me with how I execute the above googlefroogle.php file with the parameters above, from the end of my import.php script.

Thanks for any help.

This post has been edited by chalfontonline: 15 August 2008 - 02:08 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Run a php file from another php file

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6879
  • View blog
  • Posts: 31,672
  • Joined: 10-May 07

Re: Run a php file from another php file

Posted 15 August 2008 - 02:09 AM

When I need to execute php pages with options, like in your example, I write a small script with curl, lynx, or any text browser that you choose. Then place that script into the cron tab.
Was This Post Helpful? 0
  • +
  • -

#3 chalfontonline   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-August 08

Re: Run a php file from another php file

Posted 15 August 2008 - 02:15 AM

View Postno2pencil, on 15 Aug, 2008 - 02:09 AM, said:

When I need to execute php pages with options, like in your example, I write a small script with curl, lynx, or any text browser that you choose. Then place that script into the cron tab.


Thanks for the reply.

Lost me completly there. Is it not possible to call a php file from another php file.

Like the sound of your small script to place in my cron, but no idea how to do that. Could you possibly give me some more details. I am on a linux server. What would I place in the sript, what would I call it . Where do I have to save it.

Thanks again
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6879
  • View blog
  • Posts: 31,672
  • Joined: 10-May 07

Re: Run a php file from another php file

Posted 15 August 2008 - 02:33 AM

View Postchalfontonline, on 15 Aug, 2008 - 05:15 AM, said:

Is it not possible to call a php file from another php file.


The instruction you are looking for is nclude, but I'm not sure how you are trying to use it.

An example of include would be something like the following:

function.php
<?php

  function output($Input) {
	echo $Input;
  }
?>




<?php

  include function.php;

  output("Hello");

?>


Was This Post Helpful? 1
  • +
  • -

#5 chalfontonline   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-August 08

Re: Run a php file from another php file

Posted 15 August 2008 - 02:49 AM

View Postno2pencil, on 15 Aug, 2008 - 02:33 AM, said:

View Postchalfontonline, on 15 Aug, 2008 - 05:15 AM, said:

Is it not possible to call a php file from another php file.


The instruction you are looking for is nclude, but I'm not sure how you are trying to use it.

An example of include would be something like the following:

function.php
<?php

  function output($Input) {
	echo $Input;
  }
?>




<?php

  include function.php;

  output("Hello");

?>



Thanks for your help with this no2pencil

How would the code look for the file I mentioned in the original post.

Is the $input this http://www .mysite.co.uk/shop/googlefroogle.php?feed=yes&upload=yes&type=products in quotes like this

output("http://www .mysite.co.uk/shop/googlefroogle.php?feed=yes&upload=yes&type=products ");

Finding this very confusing, just my lack of knowledge
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6879
  • View blog
  • Posts: 31,672
  • Joined: 10-May 07

Re: Run a php file from another php file

Posted 15 August 2008 - 03:04 AM

I supplied a link to php.net in my post. It's a direct link to the syntax & example usage of the include command.

& no, you won't use http://

To help you best, can you give a full description of what you are trying to do, because there are two ways of going about what you are doing & I think there is some loss in translation between what you are trying to do & what you think you should do, & what I am suggesting that you do. :)
Was This Post Helpful? 0
  • +
  • -

#7 chalfontonline   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-August 08

Re: Run a php file from another php file

Posted 15 August 2008 - 03:29 AM

View Postno2pencil, on 15 Aug, 2008 - 03:04 AM, said:

I supplied a link to php.net in my post. It's a direct link to the syntax & example usage of the include command.

& no, you won't use http://

To help you best, can you give a full description of what you are trying to do, because there are two ways of going about what you are doing & I think there is some loss in translation between what you are trying to do & what you think you should do, & what I am suggesting that you do. :)


OK here goes, I hope this discription is more understandable.

Currently I have to run this
http://www .mysite.co.uk/shop/googlefroogle.php?feed=yes&upload=yes&type=products

from my browser every day to upload products to froogle google product lists.

I can not run this via cron, as my cron does not allow parameters to be set, as in feed=yes&upload=yes etc.

Setup in cron already is a file called import.php, which also resides in my shop directory. This cron is currently setup to run every hour, and it's job is to get all the product and images from my supplier and load them onto my site.

This works well. Every time the products are updated, I want to upload to the froogle google product list. Because the cron will not work with parameters, I thought it would be worth making the import script run the froogle google product list php file.

So the sequence would be like this,

CRON TASK RUNS import.php file -
import.php calls googlefroogle.php?feed=yes&upload=yes&type=products
import.php ends

both import.php and googlefroogle.php reside in the shop directory of my site.

If you think the script in the cron as you first suggested is better, I will do that.

I am very new to all this, and so need some full explanation if you can of the solution that you think is best.

I appreciate your time on this, and hope you now understand clearer what I am trying to do.
Was This Post Helpful? 0
  • +
  • -

#8 JBrace1990   User is offline

  • D.I.C Addict
  • member icon

Reputation: 112
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Run a php file from another php file

Posted 15 August 2008 - 10:44 PM

include 'http://www.mysite.co.uk/shop/googlefroogle.php?feed=yes&upload=yes&type=products';

Was This Post Helpful? 0
  • +
  • -

#9 chalfontonline   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 13-August 08

Re: Run a php file from another php file

Posted 16 August 2008 - 06:27 AM

View PostJBrace1990, on 15 Aug, 2008 - 10:44 PM, said:

include 'http://www.mysite.co.uk/shop/googlefroogle.php?feed=yes&upload=yes&type=products';


Tried that but did not work. No errors, but did not show in google base as being uploaded, so pressume it did not run.

Ran the file directly from browser, and it did show uploaded in google base, just to prove the file is working.

Not sure where to go from here ?
Was This Post Helpful? 0
  • +
  • -

#10 emahuni   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-June 12

Re: Run a php file from another php file

Posted 18 June 2012 - 02:59 AM

You need to use is curl functions.

http://www.php.net/curl for more information on curl functions.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://xxxxxxx.co.zw/tests/test_execute.php'); //the file or url to run
curl_setopt($ch, CURLOPT_HEADER, false); // i don't want a response header
curl_setopt($ch, CURLOPT_NOBODY, true); //i don't want it to display anything

//for any parameters sent like the regular http POST use the following
//$data = array('name' => 'Foo', 'file' => '@/home/user/test.png'); //similar to ?name=Foo&[email protected]/home/user/test.png
//curl_setopt($ch, CURLOPT_POST, true); 
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);

curl_close($ch);



Emmanuel Mahuni
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3837
  • View blog
  • Posts: 13,998
  • Joined: 08-August 08

Re: Run a php file from another php file

Posted 18 June 2012 - 06:53 AM

If they haven't gotten the solution in the last four years I doubt they'll get it now.
Was This Post Helpful? 1
  • +
  • -

#12 emahuni   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-June 12

Re: Run a php file from another php file

Posted 19 June 2012 - 04:25 AM

View PostCTphpnwb, on 18 June 2012 - 06:53 AM, said:

If they haven't gotten the solution in the last four years I doubt they'll get it now.


LOL

dude it's not about them, it's about others.
The internet is used as a vast library for help as well.
4 years later we are still reading.
This will help some noob.

Emmanuel Mahuni
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1