Précédent   Forum des professionnels en informatique > PHP > Langage > Fonctions
Fonctions Forum d'entraide sur les fonctions PHP. Avant de poster -> FAQ fonctions et Sources diverses
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/12/2011, 21h41   #1
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Par défaut stream_notification_callback et apc

Bonjour,
j'ai un serieux soucis que je ne comprend pas du tout ...
J'ai un script qui télécharge un fichier avec fopen fwrite et fread je suis donc allé chercher dans la doc php un script de fonction callbcak pour suivre le déroulement du script :
le voici :
Code php :
1
2
3
4
5
6
7
8
9
10
11
12
13
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
 
 
	$key = $_POST['APC_UPLOAD_PROGRESS'];
	$array = array (
		'total' => $bytes_max,
		'current' => $bytes_transferred
	);	
	apc_store($key, $array);
 
    echo $bytes_transferred;
 
}
et la le soucis c'est que apc vas renvoyer les valeurs de content et total a 0
Code json :
{"total":0,"current":0}
alors que le echo $bytes_transferred affiche correctement les valeurs souhaités :
Citation:
0
0
0
0
0
0
0
0
0
2896
4344
5792
7240
8688
...
264984
266432
267880
269328
270776
272224
273672
275120
Merci ...
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 09h50   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
montre ton script ou y'a le apc_fetch
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 10h25   #3
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Voila
Code php :
1
2
3
4
5
6
7
if(isset($_GET['id_progress'])) {
 
$rep=apc_fetch($_GET['id_progress']);		
echo json_encode($rep);
    exit;
 
}
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 10h36   #4
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
normalement t'as pas a utiliser un champs APC_UPLOAD_PROGRESS, après c'est qu'une variable mais bon, je vais testé de mon coté pour voir
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 10h43   #5
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
t'as regarder les donnéés dans la console APC ?

montre ton code avec le fopen et compagnie
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 10h47   #6
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
$url = $_POST['url'];
//recuperation du size du fichier
$remoteFile = $url;
$ch = curl_init($remoteFile);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here)
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
  echo 'cURL failed';
  exit;
}
$contentLength = 'unknown';
$status = 'unknown';
if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
  $status = (int)$matches[1];
}
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
  $contentLength = ((int)$matches[1])/1000;
}
// --
 
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
global $url;
	echo filesize("gecici/".basename($url));
 		//global $contentLength;
	$key = $_POST['APC_UPLOAD_PROGRESS'];
	$total = $bytes_transferred;
	$array = array (
		'total' => $bytes_max,
		'current' => $bytes_transferred
	);	
	apc_store($key, $array);
 
   // echo $total."<br>";
 
}
 
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
 
  $file = fopen ($url, "rb", false, $ctx);
  if ($file) {
    $newf = fopen ("gecici/".basename($url), "wb");
 
    if ($newf)
    while(!feof($file)) {
      fwrite($newf, fread($file, $contentLength ), $contentLength );
 
    }
  }
 
  if ($file) {
    fclose($file);
  }
 
  if ($newf) {
    fclose($newf);
  }
Voila après je ne sais pas comment regarder les données dans la console apc
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 10h54   #7
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
choppe les source de apc sur le site PECL, et prend le apc.php qui correspond a ta version


sinon ton code est super compliquer, pour récupérer une entête c'est get_headers et pour copier une fichier c'est copy
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h23   #8
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
copy ou move_uploaded_file ne fonctionne pas en remote ...
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h28   #9
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
Citation:
Envoyé par Onyrio Voir le message
copy ou move_uploaded_file ne fonctionne pas en remote ...
si copy fonctionne avec n'importe quel stream (même ftp et dans les deux sens)

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ob_implicit_flush();
$file_size = 0;
 
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
    global $file_size;
    switch ($notification_code) {
        case STREAM_NOTIFY_FILE_SIZE_IS:
            $file_size = $bytes_max;
            break;
        case STREAM_NOTIFY_PROGRESS:
            echo "$bytes_transferred/$file_size", "\n";
            break;
    }
}
 
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
 
$url = 'http://windows.php.net/downloads/releases/php-5.3.8-src.zip';
copy($url, basename($url), $ctx);
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h30   #10
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
je teste ça desuite
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h35   #11
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Alors ... le fichier est bien copié mais rien ne s'affiche le callback n'est pas executé on dirait ...
Ou as tu trouvé le script ?
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h38   #12
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
Citation:
Envoyé par Onyrio Voir le message
Alors ... le fichier est bien copié mais rien ne s'affiche le callback n'est pas executé on dirait ...
Ou as tu trouvé le script ?
nulle part, je l'ai fait, t'as bien PHP 5.3 ?
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h44   #13
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Citation:
Envoyé par stealth35 Voir le message
nulle part, je l'ai fait, t'as bien PHP 5.3 ?
PHP Version 5.3.3-7+squeeze3

On dirait que la callback n'est pas éxécutée
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h48   #14
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
Citation:
Envoyé par Onyrio Voir le message
PHP Version 5.3.3-7+squeeze3

On dirait que la callback n'est pas éxécutée
bizarre moi ça marche, si tu fais juste
Code :
echo $bytes_transferred, "\n";
dans le callback ?

essaye sans le copy sinon (version 5.2)

Code :
1
2
3
4
5
6
7
$source = fopen($url, 'rb', false, $ctx);
$dest = fopen(basename($url), 'wb');
 
stream_copy_to_stream($source, $dest);
 
fclose($source);
fclose($dest);
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 11h53   #15
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Citation:
Envoyé par stealth35 Voir le message

Code :
1
2
3
4
5
6
7
$source = fopen($url, 'rb', false, $ctx);
$dest = fopen(basename($url), 'wb');
 
stream_copy_to_stream($source, $dest);
 
fclose($source);
fclose($dest);
ça marche avec ça ... bizzare ...
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 12h02   #16
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
ob_implicit_flush();
$file_size = 0;
 
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
 
	$array = array (
		'total' => $bytes_max,
		'current' => $bytes_transferred
	);	
	apc_store('foo', $array);
}
 
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
 
$url = 'http://windows.php.net/downloads/releases/php-5.3.8-src.zip';
$source = fopen($url, 'rb', false, $ctx);
$dest = fopen(basename($url), 'wb');
 
stream_copy_to_stream($source, $dest);
 
fclose($source);
fclose($dest);
apc retourne toujours des valeurs a zero ...
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 13h01   #17
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
dans la console le aussi ?
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 13h09   #18
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
je ne sais pas comment afficher ta console ...
J'ai trouvé un moyen qui marche :
Code php :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
ob_implicit_flush();
$file_size = 0;
 apc_store('foo34567', 2);
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
	echo $bytes_max."<br>";
	$array = array (
		'total' => $bytes_max,
		'current' => $bytes_transferred
	);	
 
	apc_cas('foo34567', apc_fetch('foo34567'), $bytes_transferred);
 
}
 
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
 
$url = 'http://windows.php.net/downloads/releases/php-5.3.8-src.zip';
$source = fopen($url, 'rb', false, $ctx);
$dest = fopen(basename($url), 'wb');
 
stream_copy_to_stream($source, $dest);
 
fclose($source);
fclose($dest);

cependant je ne sais pas comment mettre un array avec apc_cas ...
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 13h10   #19
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
Citation:
Envoyé par Onyrio Voir le message
je ne sais pas comment afficher ta console ...
Citation:
Envoyé par stealth35
choppe les sources de apc sur le site PECL, et prend le apc.php qui correspond a ta version
...
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/12/2011, 13h16   #20
Nouveau Membre du Club
 
Homme valentin lafranca
Lycéen
Inscription : mai 2011
Messages : 74
Détails du profil
Informations personnelles :
Nom : Homme valentin lafranca
Âge : 19
Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

Informations professionnelles :
Activité : Lycéen

Informations forums :
Inscription : mai 2011
Messages : 74
Points : 26
Points : 26
Citation:
Envoyé par stealth35 Voir le message
...
Je n'est pas trouvé !
Onyrio est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h27.


 
 
 
 
Partenaires

Hébergement Web