Page 1 of 1

How can a PHP invoke another PHP?

Posted: Wed Jun 30, 2004 12:43 am
by myleow
Hi All,

I am generating WML content with a PHP file, but i need to re-invoke the same PHP file to generate the WML content again after 10 seconds. It is kinda pushing pages to the user.

I have tried the following..

push.wml

Code: Select all

<? php

  echo "<wml>";
  echo "<card blah>";
  echo "<p>";
  echo $PHP_Variable;
  echo "</p>";
  echo "</card>";
  echo "</wml>";

  if (!empty($PHP_Variable))
  {
    invoke callback.php
  }
?>
callback.php

Code: Select all

<?php
  sleep(10);
  invoke push.wml
?>
I tried using header("Location: Content"), that doesn't work because it actually sends the header to the Mobile Phone and that makes it worst because it did not activate any of the PUSH.WML content. The actual content that exist in the PUSH.WML requires at least a second for the Mobile Phone to register and activate it.

So i need a way to invoke callback.php on the server side and not sending the invokation to the Mobile Phone along with the WML content. Then the callback.php will wait 10 second on the server and then invoke PUSH.WML again.

You guys following? I don't know if i am explaining it well enough to get valid responds. Please help.

================

This is what i see from the Nokia Mobile Dev Kit's diagnos tool.

The Mobile Phone is requesting PUSH.WML then it request CALLBACK.PHP and after 10 seconds request PUSH.WML and so on so forth. So i can't use header redirection to do what i want to do.

Please help.

Thanks in advance,

Regards
Mian


feyd | last warning, use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Wed Jun 30, 2004 6:32 am
by Buddha443556

Posted: Wed Jun 30, 2004 8:09 am
by lostboy
how about using it as a function

Code: Select all

function send_wap($value)
{
  echo "<wml>"; 
  echo "<card blah>"; 
  echo "<p>"; 
  echo $value; 
  echo "</p>"; 
  echo "</card>"; 
  echo "</wml>"; 
}

while( 1=2){
  if (!empty($PHP_Variable)) 
  { 
   sleep(10); 
   send_wap($PHP_Variable); 
  } 
  [some  condition to break the loop]
}//end loop

That doesn't work

Posted: Thu Jul 01, 2004 12:41 am
by myleow
The above suggested solution does not solve the problem. I used ob_end_flush() and then sleep(2). What it really does is wait for the 2 seconds before flushing the WML content to the Mobile Phone.

I have attached the source code below.

Code: Select all

<?php

while($_SESSION["downloadlist"]!='')
{
    ob_start();
    include 'header.wml';
    session_start();

    echo "<wml>";
    echo "<card id="Testing PUSH"" title="Testing PUSH" newcontext="true">";
    echo "<onevent type="onenterforward">";
    echo "<go href="www.devnetwork.net"/>";
    echo "</onevent>";
    echo "<p>";
    echo "Testing PUSH";
    echo "</p>";
    echo "</card>";
    echo "</wml>";
    ob_end_flush();
    sleep(2);
  }
?>
As you can see from above, it is similar to the example you suggested. I actually tried your example but it doesn't work. So i am hoping that someone here knows how to push content out of a PHP file and then loop then content again.

I can only think of 2 ways to solve this problem.

The first would be looping back the own file. Which i could not get it to work.

Second would be invoking another file and then that file invoke this file. BUT i have no idea how to call another file. It is not using include because include just inline the code in that file to this one.

Here is the result from the suggestion given above.

Code: Select all

<?php
  function send_wap($j)
  {
    include 'header.wml';
    echo "<wml>";
    echo "<card id="testpush" title="test push">";
    echo "<p>";
    echo "Testing Push $j";
    echo "</p>";
    echo "</card>";
    echo "</wml>";
  }
  for ($i=0; $i<2; $i++)
  {
    sleep(2);
    send_wap($i);
  }
?>
Notice the for loop goes twice, this creates a 500 error on the Nokia Mobile Emulator browser.

If i changed it to 1 loop then it will wait for 2 seconds before sending the wml content. I just can't make it go on for more than 1 loop, which is very frustrating.

Posted: Thu Jul 01, 2004 7:31 pm
by myleow
no one knows? =(

PHP can't call another PHP file, unlike in C++ or Java?!

Posted: Thu Jul 01, 2004 7:51 pm
by John Cartwright
rewritting...

Posted: Fri Jul 02, 2004 7:23 am
by mox
What about:

eval() ?

Posted: Fri Jul 02, 2004 9:27 am
by RFairey
Are you sending headers twice in your example where you loop through it? try moving the include for header.wml outside the loop, so it is included once and not again?