View Full Version : execute .php file from php file
kalaid
Jan 28th 2008, 6:47 am
Hi Guy's
I am working with the concept of threading, Here I want to execute a same e php file more than one time simultaneously. Is there is any command to execute php file
Thanks in advance
Edit/Delete Message
Kaizoku
Jan 28th 2008, 6:54 am
You can use shell functions to execute php.
exec("php-cgi /path/to/script.php >/dev/null 2>&1");
exec("php /path/to/script.php >/dev/null 2>&1");
Or you can use wget and run it in background mode to run simultaneous script.
exec("wget -bq -o /dev/null http://www.example.com/script1.php");
exec("wget -bq -o /dev/null http://www.example.com/script2.php");
Or you can use cURL to execute simultaneously.
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/script1.php");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.example.com/script2.php");
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
$running=null;
//execute the handles
do {
curl_multi_exec($mh,$running);
} while ($running > 0);
//close the handles
curl_multi_remove_handle($ch1);
curl_multi_remove_handle($ch2);
curl_multi_close($mh);
?>
kalaid
Jan 28th 2008, 7:11 am
Hi Kaizoku
Thank's for your post
I tried using
exec("wget -bq -o /dev/null http://www.example.com/script1.php");
function, along with the file name i passed arguments, but the file is not executed. Please help me to solve this
Kaizoku
Jan 28th 2008, 7:19 am
Hi Kaizoku
Thank's for your post
I tried using
exec("wget -bq -o /dev/null http://www.example.com/script1.php");
function, along with the file name i passed arguments, but the file is not executed. Please help me to solve this
Okay it looks like you are on shared host or restricted from having extra processes.
Try this:
exec("wget -q http://www.example.com/script1.php >/dev/null 2>&1");
kalaid
Jan 28th 2008, 7:27 am
Hi Kaizoku
<?
error_reporting(0);
require_once "auth/config.php";
$link = mysql_connect($hostname, $username,$password);
if($link)
{
$dbcon = mysql_select_db($dbname,$link);
}
$str= "select * from thread where status like 'free'";
$res=mysql_query($str,$link);
while($row=mysql_fetch_array($res,MYSQL_ASSOC))
{
$tnames[]=$row['tname'];
}
$len=sizeof($tnames);
$str1= "select * from urls where status like 'TBC' limit 0,$len";
$res1=mysql_query($str1,$link);
while($row1=mysql_fetch_array($res1,MYSQL_ASSOC))
{
$url[]=$row1['url'];
}
for($i=0;$i<$len;$i++)
{
$query="update thread,urls set thread.status='busy', urls.status='busy' where tname='$tnames[$i]' and url='$url[$i]'";
$result=mysql_query($query,$link);
exec("wget -bq -o /dev/null http://localhost/sitemapprototype/crawl.php");
}
?>
Even after using above command, it is not working.
In the above code I am executing crawl.php and in crawl.php i want to update some data into the database.
Kaizoku
Jan 28th 2008, 7:34 am
That is strange, the code I gave worked on my server. What OS/Distro are you using? Are you using dedicated or shared hosting?
Also turn error_reporting to E_ALL so you will see errors and debug.
kalaid
Jan 28th 2008, 7:57 am
Hi Kaizoku
I am using windows xp os and the file which i executed kept in my local machine
Kaizoku
Jan 28th 2008, 5:44 pm
Do you have wget installed on your local box?
kalaid
Jan 28th 2008, 10:22 pm
I don't know whether wget is installed in my local machine. If I want to install what I have to do
shallowink
Jan 28th 2008, 10:33 pm
Get wget for win32 here:
http://www.christopherlewis.com/WGet/WGetFiles.htm
or here:
http://xoomer.alice.it/hherold/
Version 1.10.2 is on both sites, though the first looks like it was updated recently.
Make sure to put it somewhere in your path or call it explicitly.
Kaizoku
Jan 28th 2008, 11:13 pm
Because windows can't execute by just calling wget. It doesn't have the feature like /usr/bin in linux I think.
You have to execute wget using the absolute path.
exec("C:/path/to/wget.exe -q http://www.example.com/script1.php");
shallowink
Jan 28th 2008, 11:19 pm
I don't know anything about that, could test it though. If i wanted multi process headaches, I'd just use perl.
Thought if he used wget it would have to be somewhere in the webserver path.
kalaid
Jan 29th 2008, 2:07 am
Hi Kaizoku
I have uploaded my files into server and tried to execute with both exec() commands
//exec("wget -bq -o /dev/null http://mycollege.in/crawl.php");
exec("http://mycollege.in/crawl.php >/dev/null 2>&1");
The file crawl.php is not executed, but when i execute the file crawl.php separately then it is executed.
Our's is LINUX Shared hosting
Please help me solve this issue
Kaizoku
Jan 29th 2008, 2:14 am
Dude, you just said you were using windows, now it's linux...
kalaid
Jan 29th 2008, 2:27 am
In am writing coding for my project in my windows machine and after completing i want to upload into our site, which is linux shared hosting site.
Now it is working in windows with this function
exec("C:/path/to/wget.exe -q http://www.example.com/script1.php");
But when i upload and call the file with this either of the function
exec("wget -bq -o /dev/null http://mycollege.in/crawl.php");
exec("http://mycollege.in/crawl.php >/dev/null 2>&1");
It is not working.I want to know whether my server is not supporting wget or i have to use any absolute path for wget as in windows
Kaizoku
Jan 29th 2008, 2:45 am
exec("whereis wget", $output);
print_r($output);
Report back the results.
kalaid
Jan 29th 2008, 3:07 am
Hi Kaizoku
I got the result as
Array ( [0] => wget: /usr/bin/wget /usr/share/man/man1/wget.1.gz )
Whether i have to provide this path in exec()
Kaizoku
Jan 29th 2008, 3:09 am
I think your shared hosts restricts you to extra processes.
So try this
exec("wget -q http://mycollege.in/crawl.php");
exec("/usr/bin/wget -q http://mycollege.in/crawl.php");
If all fails, the admin probably restricts the usage of wget for normal users.
kalaid
Jan 29th 2008, 3:10 am
Hi
Also I want to pass the arguments along with the file inside exec() function.
I tried like this in windows
exec("C:/path/wget.exe -q http://localhost/sitemapprototype/crawl.php?thread=$tnames[0]&url=$url[0]");
The arguments are not passed
Kaizoku
Jan 29th 2008, 3:14 am
You need to wrap it around apostrophes. Arrays need to be wrapped around curly braces as well.
exec("C:/path/wget.exe -q 'http://localhost/sitemapprototype/crawl.php?thread={$tnames[0]}&url={$url[0]}'");
kalaid
Jan 29th 2008, 3:18 am
Hi
I tried this
exec("wget -q http://mycollege.in/crawl.php");
exec("/usr/bin/wget -q http://mycollege.in/crawl.php");
But it fails, So I have to change the access mode of wget.
kalaid
Jan 29th 2008, 3:44 am
I tried with
exec("C:/path/wget.exe -q 'http://localhost/sitemapprototype/crawl.php?thread={$tnames[0]}&url={$url[0]}'");
but the values are not passed to crawl.php file
Kaizoku
Jan 29th 2008, 3:58 am
hmmm try this:
$link = "http://localhost/sitemapprototype/".rawurlencode("crawl.php?thread={$tnames[0]}&url={$url[0]}");
exec("C:/path/wget.exe -q '{$link}'");
kalaid
Jan 29th 2008, 4:14 am
I tried still it fails
Also I tried passing ordinary variables rather than array variable even though it fails to execute.
Kaizoku
Jan 29th 2008, 4:28 am
Okay I give up...
kalaid
Jan 29th 2008, 4:35 am
ok thanks a lot for your help
Kaizoku
Jan 29th 2008, 4:36 am
Something strange with windows wget, it works perfectly fine with linux wget.
shallowink
Jan 29th 2008, 5:16 am
hey kalaid,
you could try to use wget's file option. write your string to a file and then call wget with this
exec("C:/path/wget.exe -q -i filename.txt");
kalaid
Jan 29th 2008, 7:26 am
Hi
The issue here is when i provide
$link ="http://localhost/sitemapprototype/crawl.php?uurl={$urll}&thread={$nam}";
The argument after '&' is not passed. If I provide like this
$link1 ="http://localhost/sitemapprototype/crawl.php?uurl={$urll}thread={$nam}";
The value for uurl and thread is passed along the file but i cannot get the values for uurl and thread seperately. The thread variable and the value is combined along with the uurl as there is no '&' symbol
What to do in such case
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.